Use html_safe
= link_to "A Link", link_path, :title => "A Link", :onclick => "_gaq.push(['_trackEvent', 'Category', 'Action']);".html_safe
Question
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!
Solution
Use html_safe
= link_to "A Link", link_path, :title => "A Link", :onclick => "_gaq.push(['_trackEvent', 'Category', 'Action']);".html_safe