erb in coffee script with rails 3.1

denisjacquemin picture denisjacquemin · Jun 28, 2011 · Viewed 24k times · Source

I would like to use some erb in my .coffee files, like the following example

myLatlng: new google.maps.LatLng(<%[email protected] %>, <%[email protected] %>)

I renamed my locations.js.coffee to locations.erb.coffee

but I still get the following error

Error compiling asset application.js:
ExecJS::ProgramError: Error: Parse error on line 4: Unexpected 'COMPARE'
  (in /Users/denisjacquemin/Documents/code/projects/geolog/app/assets/javascripts/locations.erb.coffee)
Served asset /application.js - 500 Internal Server Error

Answer

Arcolye picture Arcolye · Nov 23, 2011

If you want erb in the .coffee files IN YOUR VIEW folder, leave your file named as yourfilename.js.coffee, and Rails will still process the ERB, oddly enough.

To make it work in Heroku, move coffee-rails out of the assets group in your Gemfile.