how to display content with raw html how to display content with raw html ruby ruby

how to display content with raw html


Assuming Rails 3, use the raw helper method e.g.

<%= raw(@post.body) %>

Escaping HTML output is on by default in all view templates (in contrast to earlier versions where you had to use the h method to escape strings individually.)


Are you using rails 3? It automatically escapes all contents of <%= %> tags. To avoid it, do

<%= raw(@post.body) %>


I take it you're in Rails 3? One big change is that displayed text used to be raw by default, and you had to sanitize it yourself. Now it's the other way around. Call it like this:

<%= raw(@post.body) %>

And you'll get what you're looking for.