Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop auto encoding of <%= strings %> with Rails 3

I'm using rails 3. In my index.html.erb and in my index.js.erb, if I have:

<%= "string with unsafe characters' like <" %>

It will automatically be encoded to:

string with unsafe characters&quot; like &amp;

just the same as if I had used:

<%=h "string with unsafe characters' like <" %>

How do I get it to stop? I have stored some short bits of JavaScript that I need to insert into the template without it automatically encoding the string?

like image 251
christophercotton Avatar asked Dec 29 '22 17:12

christophercotton


1 Answers

Just use the raw method like this:

<%=raw "string with unsafe characters' like <" %>
like image 160
Jakub Hampl Avatar answered Jan 13 '23 15:01

Jakub Hampl