Retain Newline Characters on Rails View

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:
textarea1
Output shown as single block sentences without any wrapper.
output1
Output when the ActionView helper method simple_format is used:
output2

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 *