Retain Newline Characters on Rails View

Neelkanth Ram

17 sec read

In Rails view, if you want to retain and display newline characters that was entered by the user in text area, then the simple solution to use simple_format .

If you use <%= @profile.description %> , then the carriage returns gets discarded.
The simple way is to use <%= simple_format(@profile.description) %>.
Text entered by user in a textarea field:
Output shown as single block sentences without any wrapper.
Output when the ActionView helper method simple_format is used:

Related posts:

One Reply to “Retain Newline Characters on Rails View”

Leave a Reply

Your email address will not be published. Required fields are marked *