How to pass ruby variable to JavaScript function. Here the ruby variable is an active record object.
= label = @label // active record object
- @x = 5
= javascript_tag "alert(#{ j(@x.to_json)});" // Working
= javascript_tag "proj.app.custom(#{ j(label.to_json)})" // Not working
proj.app.custom is a javascript function.
proj.app.custom = function(param) {
};
I am getting the following error
Uncaught SyntaxError: Invalid or unexpected token
label? Doeslabel.inspect.to_sreturn something that looks like whatproj.app.customwould accept? What isproj.app.customand what parameters does it expect?@x).javascript_tag?