AdamNYC AdamNYC - 2 months ago 9x
Ruby Question

Making jQuery works with Turbolinks

I have a Rails 4 app, which uses

. My understanding is that
breaks jQuery code, as Turbolinks does not load new page, but only get new elements.

Therefore, navigating to new page may not trigger
, although it always triggers
, and thus new jQuery code won't initialize.

I have a lot of jQuery code, so I don't want to modify my jQuery code to be compatible with Turbolinks.

Is it possible to add a javascript code to my application.js that overwrites
event to include
as well? How should I do it?


Rather than wait for $(document).ready to fire for your jQuery, just use page:load instead:

$(document).on 'page:load' ->
  <your code>

Alternatively, you can set up the jquery.turbolinks gem: