ehsan ehsan - 4 months ago 12
Ruby Question

How to print newline in rails view?

This is my

erb
:

<h1>Demo#hello</h1>
<p>This is my first Ruby on Rails Application :) </p>

<%= 1+2 %>

<% 10.times do %>
<%= "Hello,World\n" %>
<% end %>


which results in :

Demo#hello

This is my first Ruby on Rails Application :)
3 Hello,World Hello,World Hello,World Hello,World Hello,World Hello,World Hello,World Hello,World Hello,World Hello,World


I know...know there is some tag called
<br/>
which prints new line...
but I am curious if it could be done with "\n"....

Thanks in advance!

Answer

Ordinarily in HTML the newline character is treated as whitespace. But you can use CSS to break lines at newline characters:

white-space:pre-wrap;