RailsCasts Pro episodes are now free!

Learn more or hide this

benmmurphy's Profile

GitHub User: benmmurphy

Comments by

Avatar

that should be:

then

window.myvar == "<foo>"
Avatar

one problem with using javascript tags is the 'j' escape function in rails doesn't work correctly or doesn't work how you might expect it to work. the string you send it is not always preserved and is corrupted in subtle ways.

for example if you have a string like:

"<foo>"

and if you have:

<%= javascript_tag do %>
  window.myvar = '<%= j "<foo>" %>';
  alert(window.myvar);
<% end %>

then window.myvar == "<foo>"

the j function really has to replace '<' and '>' with '\u003C' and '\u003E'.