Search code examples
htmlruby-on-railsredcloth

How do I parse HTML in Rails?


I have a string with html tags in it saved.

=> "<p>hey man this is crazy g funk</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)

Solution

  • 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;.