Reputation: 4598
I'd like to render multiline text in Rails, the action looks like:
def mutli_text
render :text => 'Word1\nWord2'
end
and I'd expect the response to be :
Word1
Word2
unfortunatly I get Word1\nWord2
Any help would be appreciated
(The action must render a multiline response to get the autocomplete jquery plugin working)
Upvotes: 4
Views: 5552
Reputation: 1573
Just render the text as plain
. You can even change the content type to csv if you want to.
render :plain => 'Word1\nWord2', :content_type => "text/csv"
Upvotes: 0
Reputation: 3322
you can actually do something like this:
(render :text => "line1\nline2").gsub("\n",'<br />')
It at least works on #render within a view (using HAML). I haven't tried it within a controller action.
Upvotes: 3
Reputation: 187024
"Word1\nWord2"
You have to use double quotes to be able to use escaped characters.
But if you want to have that actually be a line break in the browser, you need to make it an actual html tag.
'Word1<br/>Word2'
Or even:
"Word1<br/>\nWord2"
Upvotes: 14