Using $(document).ready() with turbolinks on Rails

Quick-tip:

Sometimes, when you’re following turbolinks links, you might find that the new page that you’re loading doesn’t trigger its $(document).ready() function.

A quick way to solve this is to use the jquery-turbolinks gem.

Set it up, and update your Gemfile to add the following:

Ensure that jquery.turbolinks is loaded after the jquery requires

//= require jquery...
//= require turbolinks
//= require jquery.turbolinks