To my understanding, all of your JavaScript gets merged into 1 file. Rails does this by default when it adds //= require_tree . to the bottom of your appl
//= require_tree .
appl
Philip's answer is quite good. Here is the code to make it work:
In application.html.erb:
Assuming your controller is called Projects, that will generate:
Then in projects.js.coffee:
jQuery -> if $('body.projects').length > 0 $('h1').click -> alert 'you clicked on an h1 in Projects'