In my rails 3.1.3 app, I'd like to insert some ERB code in my javascript file but it's not being parsed for some reason:
# app/assets/javascripts/application.js
//= require_tree ./shared
# app/assets/javascripts/shared/shared.js.erb
MM.loading = '<img src="<%= asset_path("icons/ajax-loader.gif") >">';
Gets rendered like this in /application.js
:
MM.loading = '<img src=" asset_path("icons/ajax-loader.gif") >">';
I can't see any extra steps in the rails guides - is there something I'm missing? Btw I'm using haml for the view files, and also tried the above with .js.haml
, enclosing in #{...}
.