Using turbolinks in a Rails link_to

Edit for Rails 5+: @ManishShrivastava correctly pointed out the different syntax needed for Rails 5 as shown in Joseph’s answer. <%= link_to(‘Giraffe’, @giraffe, data: { turbolinks: false }) %> For Rails 4 and below Originally I thought you needed to use the hash rocket syntax for the symbol but that isn’t the case. You can … Read more

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

Rather than listen to the ready event, you need to hook in to an event fired by Turbolinks for every page visit. Unfortunately, Turbolinks 5 (which is the version that appears in Rails 5) has been re-written, and does not use the same event names as in previous versions of Turbolinks, causing the answers mentioned … Read more

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