Rails 4 turbo-link prevents jQuery scripts from working

$(document).ready(function(){ doesn’t really work with Turbolinks. Turbolinks: … makes following links in your web application faster. Instead of letting the browser recompile the JavaScript and CSS between each page change, it keeps the current page instance alive and replaces only the body and the title in the head. So the page is only loaded once … Read more

Rails 4: how to use $(document).ready() with turbo-links

Here’s what I do… CoffeeScript: ready = -> …your coffeescript goes here… $(document).ready(ready) $(document).on(‘page:load’, ready) last line listens for page load which is what turbo links will trigger. Edit…adding Javascript version (per request): var ready; ready = function() { …your javascript goes here… }; $(document).ready(ready); $(document).on(‘page:load’, ready); Edit 2…For Rails 5 (Turbolinks 5) page:load becomes … Read more