ruby on rails - Using to_json gives me illegal character -


i passed ruby variable javascript using to_json method, console returns me error saying "syntaxerror: illegal character" following line:

var home = #{@home.to_json}; 

does knows whats wrong?

if in .erb file can following:

var home = <%= @home.to_json %>; 

otherwise (haml or else) use parsejson method jquery in combination ruby's string interpolation:

var home = $.parsejson("#{@home.to_json}"); 

more information parsejson method can found here.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -