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

What is the difference between .erb , .rhtml and .html.erb?

Nothing, really. It’s just a change of philosophy between Rails 1 and Rails 2. Before Rails 2, you had file.rhtml, file.rxml and file.rjs. In Rails, that changed to file.content_type.template_engine. So with file.html.erb, the content type is html and the template engine is ERb. rxml is now xml.builder and rjs should now (mostly) be js.rjs In … Read more

Ruby templates: How to pass variables into inlined ERB?

For a simple solution, use OpenStruct: require ‘erb’ require ‘ostruct’ namespace = OpenStruct.new(name: ‘Joan’, last: ‘Maragall’) template=”Name: <%= name %> <%= last %>” result = ERB.new(template).result(namespace.instance_eval { binding }) #=> Name: Joan Maragall The code above is simple enough but has (at least) two problems: 1) Since it relies on OpenStruct, an access to a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)