In my javascript response to a form that was submitted with data-remote=true
, I have this line:
my_function("<%[email protected]_json%>")
But the arg passed to my_function
is filled with "
, which my javascript fails to interpret as an object. I assume I need to escape <%[email protected]_json%>
somehow, but I don't know which javascript function to use. Any ideas?
By default everything you write to template using <%= %>
is escaped. To prevent Rails from doing that you can use raw
helper:
my_function("<%= raw @object.to_json %>")