rails render helper to return a p tag with '\n' as new line

haml, html, ruby-on-rails

Solution

Try `simple_format`, which will add the `<p>` tag as well as translate `\n` to `<br>` etc.

Specifically:

Two or more consecutive newlines(\n\n) are considered as a paragraph and wrapped in `<p>` tags. One newline (\n) is considered as a linebreak and a `<br />` tag is appended.

Problem

I am getting this string with the '\n' inside and I would like to display a new line where is has the '\n' rather than displaying the raw strings inside the fruits.description ``` fruits.description: 'This is an red apple \n It is also very sweet' ``` my render helper method ``` def get_description(fruits) if fruits.type == 'apple' haml_tag 'p', fruits.description, {id: fruits.id} end end ``` I want the strings to display so that is like this ``` This is an red apple It is also very sweet ```

Original source