simple_format

simple_format(text, html_options = {}, options = {})

Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines(nn) are considered as a paragraph and wrapped in

tags. One newline (n) is considered as a linebreak and a
tag is appended. This method does not remove the newlines from the text.

比如說我們在表單欄位中輸入

1
2
3
4
5
1st line of 1st post
2nd line
3rd line
2nd paragraph

代碼是 <%= post.content %>

結果是

Rails111 2016-06-29 19-24-55.png

Rails111 2016-06-29 19-25-40.png

代碼是 <%= simple_format(post.content) %>

結果是

Rails111 2016-06-29 19-23-26.png

Rails111 2016-06-29 19-23-51.png

很明顯能看出差別