Render multiline text with Rails?

I would like to make multi-line text in Rails, the action looks like this:

def mutli_text
  render :text => 'Word1\nWord2'
end

and I expect the answer to be:

Word1
Word2

Sorry, I get Word1 \ nWord2

Any help would be appreciated

(The action should display a multi-line response in order to get the jquery autocomplete plugin)

+3
source share
3 answers
"Word1\nWord2"

You need to use double quotes to use escaped characters.

But if you want it to actually be a line break in the browser, you need to make it the actual html tag.

'Word1<br/>Word2'

Or even:

"Word1<br/>\nWord2"
+14
source

you can really do something like this:

(render :text => "line1\nline2").gsub("\n",'<br />')

, , #render ( HAML). .

+2

plain. csv, .

render :plain => 'Word1\nWord2', :content_type => "text/csv"
0
source

Source: https://habr.com/ru/post/1703754/


All Articles