Rails: access controller instance variable in CoffeeScript or JavaScript asset file
a couple of ways I have done this in the past put the data in hidden fields, access the data in js/coffee # single value <%= hidden_field_tag “foo_name”, @foo.name, { :id => “foo-name” } %> $(‘#foo-name’).val(); # when the ‘value’ has multiple attributes <%= hidden_field_tag “foo”, @foo.id, { :id => “foo”, “data-first-name” => @foo.first_name, “data-last-name” … Read more