title: Page specific javascript files in Rails 3.1
body: <p>I've been doing research on this:</p>
  
  <p><a href="https://stackoverflow.com/questions/6167805/using-rails-3-1-where-do-you-put-your-page-specific-javascript-code">Using Rails 3.1, where do you put your &quot;page specific&quot; javascript code?</a></p>
  
  <p>But I have yet to see a satisfactory answer, which also makes me question whether I'm doing something wrong.</p>
  
  <p>Here's my mental model: for different views, I'm going to have different</p>
  
  <pre><code>$(document).ready(....)
  </code></pre>
  
  <p>blocks, that obviously reference elements that are very specific to that page.  I don't want to pollute things by loading that code for every single page and somehow trying to figure out how to only execute it when on specific pages; that seems pretty ugly.</p>
  
  <p>My intuition, admittedly not backed up by any preliminary experiments, is that the ideal thing would be to:</p>
  
  <ol>
  <li>Load application wide code from application.js.</li>
  <li>Load shared controller code from something like assets/controller_name/shared.js</li>
  <li>Load view-specific code from something like assets/controller_name/show.js</li>
  </ol>
  
  <p>Off the top of my head.  The helper would, the first time it ran, check if the file exists and, if so, do a javascript_include for it.</p>
  
  <p>Perhaps this has some performance issues compared to the "let's just wrap the whole thing up in a big sticky ball and send it all" approach, but seems like a better approach to compartmentalizing code.  </p>
  
  <p>However, as above, I get the feeling I'm missing something.  Is $(document).ready on a per-page basis a bad idea?  Should that just be in the template and call a page specific bit of JS from application.js?  The linked article above comes to that conclusion, but I don't like the image I'm getting in my head of one huge $(document).ready riddled with if this, if that, if the other thing.</p>