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
Post a Comment