Hi,
I am having problems when trying to use a rails variable within javascript code.
For example, I might define a link_to_remote, with parameter
:complete => "alert('my_var');"
If my_var = "I'm testing."
, then the javascript code will break due to the single quote closing the code prematurely. If I try using escape_javascript(my_var)
so that the quote gets turned into \'
, it doesn't seem to fix the problem.
I've noticed that when you try alert('I\'m testing');
there's a problem, but if you do alert('I\\'m testing')
, it works. Since escape_javascript only turns '
into \'
, rather than \\'
, does somebody have a suggestion for how to handle this?
Thanks! Eric