Rails3 and safe nl2br !

前端 未结 3 1379
南笙
南笙 2021-02-04 05:33

I have a system for the users to be able to post comments.

The comments are grasped into a textarea.

My problem is to format the comments with br tag to replace

3条回答
  •  忘了有多久
    2021-02-04 06:12

    As Ryan Bigg suggested simple_format is the best tool for the job: it's 'l safe' and much neater than other solutions.

    so for @var:

    <%= simple_format(@var) %>
    

    If you need to sanitize the text to get rid of HTML tags, you should do this before passing it to simple_format

    http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format

提交回复
热议问题