title: How to run $(document).on 'ready' with Turbolinks 5?
body: <p>In a Rails app I have a coffeescript function that should run after the DOM has loaded</p>
  
  <pre><code>$(document).ready -&gt;
    # do some stuff
  </code></pre>
  
  <p>It used to be that I could ensure these functions also work across Turbolinks page refreshes by editing as follows </p>
  
  <pre><code>$(document).on 'ready page:change', -&gt;
    # do some stuff
  </code></pre>
  
  <p>I've just upgraded to Rails 5 and Turbolinks 5, and these functions are no longer being called correctly. </p>
  
  <p>After much searching, I've tried numerous variations, including </p>
  
  <pre><code>$(document).on 'ready', -&gt;
  $(document).ready -&gt;
  $(document).on "turbolinks:load", -&gt;
  $(document).on "page:load", -&gt;
  $(document).on "page:change", -&gt;
  # and as suggested by the [Turbolinks readme][1]
  document.addEventListener 'turbolinks:load', -&gt;
  </code></pre>
  
  <p>I have also tried these with and without <a href="https://github.com/kossnocorp/jquery.turbolinks" rel="nofollow noreferrer">jquery.tubolinks</a> installed, and with the turbolinks-compatibility patch suggested <a href="https://github.com/kossnocorp/jquery.turbolinks/issues/61" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I must be missing something obvious! What is the correct syntax to ensure functions run after the DOM is loaded for both page loads and Turbolink loads? </p>