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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With