开发者

How do I parse HTML in Rails?

开发者 https://www.devze.com 2023-01-27 11:01 出处:网络
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 eas

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

精彩评论

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

关注公众号