I am trying to save a long multi-paragraph text description in my database in a text attribute. The problem is that when I render this text, all the formatting is missing and it appears as one long string.
Is there any way to keep the line breaks?
I am trying to save a long multi-paragraph text description in my database in a text attribute. The problem is that when I render this text, all the formatting is missing and it appears as one long string.
Is there any way to keep the line breaks?
You can use the simple_format
It will adds formatting rules to the text.
In case if you want to use the formatted description in many places. You can add a method to the model.
For example if you have a model Post with field description
Then you can add a method in the model so that when ever if you use this method formatting will be applied.
class ContentItem < ActiveRecord::Base
def formatted_description
return simple_format(self.description)
end
end