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

前端 未结 9 1188
予麋鹿
予麋鹿 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:16

    You'll need to convert the plain text of the textarea to HTML.

    At the most basic level you could run a string replacement:

     message_content.gsub! /\n/, '
    '

    You could also use a special format like Markdown (Ruby library: BlueCloth) or Textile (Ruby library: RedCloth).

提交回复
热议问题