1

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)
Trip
  • 26,756
  • 46
  • 158
  • 277

2 Answers2

5

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

jonnii
  • 28,019
  • 8
  • 80
  • 108
  • Thanks! I knew it was something simple. It was so simple, I had very little idea on how to describe it. Thank you – Trip Nov 30 '10 at 20:42
1

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

noodl
  • 17,143
  • 3
  • 57
  • 55
  • Yes so instead of seeing the tags, I see an actually parsed paragraph or h1, or h2 or some specific class i make up in my css. – Trip Nov 30 '10 at 19:42
  • You're still not making any sense. "See" it in what? A printed page? A terminal window? A browser window? "actually parsed html" is meaningless, unless you want to "see" a graphical representation of a syntax tree in memory. – noodl Nov 30 '10 at 19:47