Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

how to get new line to display in rails

<%= obj.description %>
Even though your value may be "One  	  
  
  Two", it will show up on the screen as "One Two".

To get those new line characters to actually separate the lines when displayed, you'll need to convert them to HTML before rendering:

<%= obj.description.gsub(/
/, '<br/>') %>
Of course, if users are entering data that will be included in your HTML, you should be escaping the values to protect against XSS. If new lines are the only thing you need to support, it should be as simple as this:

<%= h(obj.description).gsub(/
/, '<br/>') %>
 
PREVIOUS NEXT
Tagged: #line #display #rails
ADD COMMENT
Topic
Name
2+1 =