Ruby on Rails: how to render a string as HTML?

Posted by Tim on Stack Overflow See other posts from Stack Overflow or by Tim
Published on 2011-01-02T03:12:27Z Indexed on 2011/01/02 3:54 UTC
Read the original article Hit count: 233

Filed under:
|
|
|

I have

@str = "<b>Hi</b>"

and in my erb view:

<%= @str >

What will display on the page is: <b>Hi</b> when what I really want is Hi. What's the ruby way to "interpret" a string as HTML markup?


Edit: the case where

@str = "<span class=\"classname\">hello</span>"

If in my view I do

<%raw @str %>

The HTML source code is <span class=\"classname\">hello</span> where what I really want is <span class="classname">hello</span> (without the backslashes that were escaping the double quotes). What's the best way to "unescape" those double quotes?

© Stack Overflow or respective owner

Related posts about html

Related posts about ruby-on-rails