Rails 3: How to display properly text from “textarea”?

前端 未结 9 1271
予麋鹿
予麋鹿 2021-01-31 15:31

In my Rails 3 application I use textarea to let users to write a new message in a forum.

However, when the message is displayed, all newlines look like spac

9条回答
  •  青春惊慌失措
    2021-01-31 16:26

    If someone still gets redirected here and uses Rails 4: http://apidock.com/rails/v4.0.2/ActionView/Helpers/TextHelper/simple_format

    You can now specify the tag it gets wrapped in (defaults to p) like so:

    simple_format(my_text, {}, wrapper_tag: "div")
    # => "
    Here is some basic text...\n
    ...with a line break.
    "

提交回复
热议问题