I am using Ruby on Rails 3.2.2 and I would like to know how to “output” / “reproduce” “blank lines” (stored in a database column Type TEXT) in a rendered view file. That is, in my database column Type TEXT I have stored the following data (note: blank lines are really the ones present in the data):
Line 1
Line 2
Line 3
Line 4
...
In order to make the outputted text (in front-end content) to “follows” / “reflects” “spaces” (for the above case) accordingly to data stored in the database, for example, I would like to output some HTML code as like the following:
Line 1<br/>
Line 2<br/><br/>
Line 3<br/><br/><br/>
Line 4
...
… or something else that makes that I would like to accomplish.
In other words, I need some formatting of raw database data to be outputted as much as possible like HTML code would be. How it is possible in a correct and not dangerous (for example, there may be problems related to Cross-Site Request Forgery – CSRF) way?
If you don’t need any formatting other than your newlines then you could use a
<pre>:The
<%= %>will take care of HTML encoding everything and the<pre>will take care of formatting your line breaks.