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

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -