Jackie Chan
Jackie Chan

Reputation: 2660

html.erb doesn't recognize html tags?

New to RoR, so please don't kill me ;)

Was wondering why does not Rails 3 recognize HTML tags retrieved from database?

For example,

         Name   Content                     
         Title  <b>Great</b>    Show    Edit    Destroy

I wanted to have Content to be bold and put < b > tag around it, when it retrieves from a database it looks like a plain English.

Any thoughts?

Thank you in advance.

Upvotes: 0

Views: 335

Answers (2)

josemota
josemota

Reputation: 984

Even though it is unsafe to deliberately output HTML from the DB, you should call raw on the content you're trying to print.

<%= raw @object.my_content %>

Upvotes: 1

pdu
pdu

Reputation: 10423

If I got this right, you need to do this:

<%= myrecord.content.html_safe %>

to get "real" html and not just escaped html code.

Upvotes: 2

Related Questions