开发者

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

开发者 https://www.devze.com 2022-12-30 01:30 出处:网络
I\'m using rails 3. In myindex.开发者_开发知识库html.erb and in my index.js.erb, if I have: <%= \"string with unsafe characters\' like <\" %>

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?


Just use the raw method like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号