Search
 
SCRIPT & CODE EXAMPLE
 

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/>') %>
Comment

PREVIOUS NEXT
Code Example
Ruby :: function is uninitialized constant ruby 
Ruby :: ruby ||= 
Ruby :: how to destroy a migration in rails 
Ruby :: ruby substring remove 
Ruby :: conditional operator in ruby 
Ruby :: ruby string to symbol 
Ruby :: ruby timestamp 
Ruby :: generate csv ruby 
Ruby :: shopify: how to show percentage discount saved 
Ruby :: new line in ruby 
Ruby :: rails route list 
Ruby :: ruby hello 
Ruby :: installing ruby version using Rbenv 
Ruby :: rails store array in database 
Ruby :: ruby delete first element of array 
Ruby :: ruby hello world 
Ruby :: true sting to true in rails 
Ruby :: all rails g model types 
Ruby :: each_cons with index ruby 
Ruby :: rails link_to example 
Ruby :: formatting a floating point number in ruby 
Ruby :: ruby shortcut to self.call 
Ruby :: rails prevent division by zero 
Ruby :: how to pass locals in rails partial 
Ruby :: rails format number k - m 
Ruby :: singning in using username rails 
Ruby :: rails activerecord saved_change_to 
R :: convert latin accents to ascii R 
R :: How to Export a DataFrame to Excel File in R 
R :: merge several data frames in r 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =