unobtrusive javascript -> attaching a .js.erb page

i saw on one of the railscasts that using unobtrusive javascript, you
attach your javascript to your page like so:

if your view is:


you could add a page named:


and that javascript would be included on the load for that page.

for some reason, it is not working for me..

is there something i need to do to trigger this behavior?


There is no such behaviour in Rails; I think you might have
misunderstood the screencast.

Assuming you are talking about this:

then the 'index.js.erb' is rendered when your browser makes an AJAX
request to the 'index' action (in the same way that 'index.html.erb'
is rendered when your browser makes an ordinary request to the index

These are two completely separate requests. index.js.erb is *not*
being inserted into a script tag in index.html.erb.

If you want that kind of thing to happen, you'll need to write a
custom view helper (and probably choose a more appropriate path for
your automatically-included JavaScript files, so that they don't
conflict with the standard behaviour described above).