Answers for "rails new line in string"

1

how to get new line to display in rails

<%= obj.description %>
Even though your value may be "One  t  n  n  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(/n/, '<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(/n/, '<br/>') %>
Posted by: Guest on February-17-2020
0

new line in ruby

# For a new line, insert n
print "hello", "n", "hello", "n"

# puts automatically adds new line at end of text
puts "run"

# also use n in strings
text = "The quick, brown foxnjumped"
print text;
Posted by: Guest on November-29-2021

Browse Popular Code Answers by Language