title: Rails 4 turbo-link prevents jQuery scripts from working
body: <p>I'm building a Rails 4 app and I have a few scattered js files that I'm trying to include "the rails way". I moved jquery plugins into the /vendor/assets/javascripts and I updated the manifest (application.js) to require them. When I load the pages locally I see that they appear correctly.</p>
  
  <p>However, I'm getting inconsistent behavior from one of the scripts that's compiled. I have a controller-specific js file called projects.js which is referenced in the application.js via the use of <code>require_tree .</code>:</p>
  
  <pre><code>//= require jquery
  //= require jquery_ujs
  //= require turbolinks
  //= require bootstrap.min
  //= require jquery.form.min
  //= require_tree .
  </code></pre>
  
  <p>I see the file is included correctly, and it works... half the time. The other half of the time, the stuff in projects.js doesn't seem to do anything (it's mostly jquery animations and some ajax requests). When it doesn't work, I'll click buttons a couple times, nothing will happen, and then I'll throw this error:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'position' of null 
  turbolinks.js?body=1:75
  </code></pre>
  
  <p>This never happened when the scripts were in the individual views (the wrong way), so I'm fairly certain the problem is not with my javascript code. One other potentially relevant details is that the stuff in projects.js is wrapped in a <code>$(document).ready(function(){</code>. Also, I'm testing in development mode so the javascripts and css are not combined by the asset pipeline.</p>
  
  <p>Any idea what's going on here? I'm new to Rails but I've done my best to follow all the conventions.</p>
  
  <p><strong>Update!</strong></p>
  
  <p>It's predictable <em>when</em> my project scripts don't work. The first page load works every time. Then I click one link to a new page which uses my project.js behaviors and the <em>second</em> page never works. I click a few times and eventually throw the error above. I'm still not sure why, but I'm suspecting this is related to turbo-linking.</p>