Allow HTML String – Ruby on Rails

Just a quick post on how to prevent escaping for HTML within a string. Simply use html_safe?.

i.e. The following will show the bold tags as text:

<%= "<b>GOOOOOOOGLE</b>">


Whereas once we add html_safe the text will be displayed in bold:

<%= ("<b>GOOOOOOOGLE</b>").html_safe?>


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.