title: how should I include a coffeescript file on only one page?
body: <p>Edit: a year later if I was going to do this again I'd do it with curl.js instead of Rails asset pipeline. </p>
  
  <p>Related: <a href="https://stackoverflow.com/questions/3437585/best-way-to-add-page-specific-javascript-in-a-rails-3-app">Best way to add page specific javascript in a Rails 3 app?</a></p>
  
  <p>I'm writing an app and using coffeescript to generate all of the js. That's why the related question doesn't do what I need. </p>
  
  <p>I'd like to be able to put a coffeescript file in a subfolder of my assets directory and have that .coffee file only get served up on one page. The page is on a named route </p>
  
  <p><code>match 'myNotifications' =&gt; 'user#notifications'</code> </p>
  
  <p>The most obvious thing to do was to put the .coffee file in <code>assets\javascripts\user\index.js.coffee</code>. But after reading the docs about assets I'm unclear. </p>
  
  <p>I read this line (from <a href="http://guides.rubyonrails.org/asset_pipeline.html" rel="nofollow noreferrer">http://guides.rubyonrails.org/asset_pipeline.html</a>): </p>
  
  <blockquote>
    <p>You should put any JavaScript or CSS unique to a controller inside
    their respective asset files, as these files can then be loaded just
    for these controllers with lines such as &lt;%= javascript_include_tag
    params[:controller] %> or &lt;%= stylesheet_link_tag params[:controller]
    %>.</p>
  </blockquote>
  
  <p>Ok cool, so I put the page specific js in <code>assets\javascripts\user.js.coffee</code>. Then I reloaded my home page, Ctrl F5. The user.js file is still being loaded on the homepage. Tested with <code>$ -&gt; alert 'ready from users controller'</code>; seeing that alert when I load the homepage.  </p>
  
  <p>Does Rails have a way to have a per-page coffeescript file that will only be served up with that page? Am I reading the manual wrong? Is there a place in the assets folder that I can put .coffee files where they won't get loaded with every page?</p>
  
  <p><strong>Update</strong>: Looks like I might <a href="http://railscasts.com/episodes/279-understanding-the-asset-pipeline?view=asciicast" rel="nofollow noreferrer">have an answer</a>: </p>
  
  <blockquote>
    <p>There are a couple of ways that we can get around this problem. We
    could use require_directory instead of require_tree as this will only
    load the files in the current directory and not in subdirectories. If
    we want more control over the included files we can require them
    separately instead of including the whole directory. Alternatively we
    could move the JavaScript files that we want to be included on all
    pages into a public subdirectory. We can then use require_tree
    ./public to include just those files.</p>
  </blockquote>
  
  <p>I'll give that a shot in the AM. </p>