In Rails, how can I allow some html in a text area?

前端 未结 6 2950
灰色年华
灰色年华 2021-02-19 21:35

I have a Rails app (blog) that I am creating. Very basic stuff. In my content area I have a text area for the content of the post. I am needing to include some html in the text

6条回答
  •  没有蜡笔的小新
    2021-02-19 22:03

    Are you looking for something similar to the bold, italic, ... options you get when posting in stackoverflow? If so, I would suggest Markitup, a text-editor plugin for jQuery. Once you get this set-up, you'll be able to enter mark up in your text area (e.g. Markdown, bbcode, ...). When you actually display the result on the page, you simply need to have Ruby parse the mark up language you chose.

    E.g.

    <%= @user.bio.bb_code %>
    

    Using this method, you allow your users enter styled text in a safe fashion.

提交回复
热议问题