I try to use scaffolding in rails to build a blog. I save my blog's content as :text. However, when I see the view. It can only show in one line. It looks not good.
How can I solve this problem?
Your database stores text, not HTML. In HTML line breaks are ignored unless they are marked up with relevant HTML tags. For example, a break between two paragraphs should be marked by the end of one <p>
element and the beginning of another, and a single line break should be represented by a <br>
tag.
Rails' simple_format
helper converts text to HTML by replacing line breaks with HTML tags.
So instead of something like this:
<p><%= @post.content %></p>
You would do this:
<%= simple_format @post.content %>