Today’s gotcha: CoffeeScript templates in Rails work in development but not production by default

By Paul LeaderJanuary 11, 2012 | Bug of the Day, Development, Thoughts from the team

Deployment is always a bit of a pain. No matter how hard you try there will almost always be a subtle difference between your dev and production environments (which is why ideally you should have a deployment test environment).

I had an odd bug today when deploying a Rails app. I have an AJAX call, that returns a javascript block. The template is actually a CoffeeScript file with the name check.js.coffee, the idea being that the CoffeeScript gets compiled to JavaScript before being sent out.

The application is looking for check.js.erb or something similar. It doesn’t know what to do with the CoffeeScript file.

It turns out that Rails won’t compile CoffeeScript templates by default, but you can install the Coffeebean gem and it magically works. It also has view helpers which let you drop CoffeeScript into an erb template like this…