Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onclick event in Slim not working - converting ' to &#x27

I'm trying to set up a Google Analytics goal - an event to be recorded whenever someone clicks on a certain link on my site. I'm using the Slim templating language and Rails.

The Javascript snippet I need to insert is:

onClick="_gaq.push(['_trackEvent', 'Category', 'Action']);"

The code I have is:

= link_to "A Link", link_path, :title => "A Link", :onclick => "_gaq.push(['_trackEvent', 'Category', 'Action']);"

But clicks on this aren't registering (looking at the console), and the view-source shows this:

onclick="_gaq.push(['_trackEvent', 'Category', 'Action']);"

Somehow the ' is getting converted. How can I stop this? I've tried using a pipe | but I don't think you can nest on link_tos.

Thanks for any help! I've searched Google and StackOverflow and couldn't find anything on my own. This is frustrating and I know the fix will be simple!

like image 505
Tebbers Avatar asked Nov 19 '25 01:11

Tebbers


1 Answers

Use html_safe

= link_to "A Link", link_path, :title => "A Link", :onclick => "_gaq.push(['_trackEvent', 'Category', 'Action']);".html_safe
like image 183
bprayudha Avatar answered Nov 21 '25 14:11

bprayudha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!