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 <p>
.
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..
精彩评论