Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing single quotes being escaped in image_tag onClick in .ERB

I have this line of code in my ERB file:

<% image_tag("foo.png", :onClick => "do_x('param')") %>

This produces the bad HTML:

<img src="/assets/foo.png" onClick="do_x(&#27;param&#27;)" />

I've tried using:

<% raw image_tag("foo.png", :onClick => "do_x('param')") %>

But that makes no difference. I'm running Rails 3.2.14.

like image 505
Ken Y-N Avatar asked Feb 15 '23 10:02

Ken Y-N


1 Answers

Try use <%= image_tag("foo.png", :onClick => "do_x('param')".html_safe ) %>.

Because your string include quotes that will be transferred default :)

like image 114
Bigxiang Avatar answered May 02 '23 00:05

Bigxiang