Rail UJS with json

189 Views Asked by At

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 &quot;, 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?

1

There are 1 best solutions below

0
On BEST ANSWER

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 %>")