开发者

How do I parse HTML in Rails?

I have a string with html tags in it saved.

=> "<p>hey man this is crazy g fun开发者_开发问答k</p>\n<p>here i come with another crazy message from..</p>\n<p>dj eassssy d!@#!.</p>"

How do you parse this so that it displays the way the HTML tags are implying?

I tried:

= Post.text
=h Post.text
= RedCloth.new(Post.text).to_html
= Hpricot(Post.text)


You want to do this:

<%= raw Post.text %>

or in haml

= raw Post.text

The reason is because rails escapes your html and will convert <p> into &lt;p&gt;.


Generally one parses html with html parsers. What do you mean "so that it displays the way the HTML tags are implying"? Displays on what? Presumably not a web browser..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜