Monday, March 28, 2016

Rails 4 - Disable Turbo Links

Turbolinks is included in Rails 4. It is meant to implement fast reloading by only reloading changed to your app but I am okay with disabling Turbo links. It messes up a lot of the functionality with gems. (https://plus.google.com/+YehudaKatz/posts/A65agXRynUn)

If you need to refresh your page to see your gem them try disabling turbo links and it probably will be better.

I am trying to use the jQuery date picker. What a pain. There are some really lame, inline work arounds to disable turbo links on a per-line basis but I am just going to see what happens if I disable the entire gem.

So I decided to try the Bootstrap datepicker but then I realized that I am using Skeleton so why would I include all of Bootstrap for that one function. Plus it is no easier.

Back to jQuery UI's date picker

http://guides.rubyonrails.org/working_with_javascript_in_rails.html#turbolinks

How Turbolinks Works 

Turbolinks attaches a click handler to all <a> on the page. If your browser supports PushState, Turbolinks will make an Ajax request for the page, parse the response, and replace the entire <body> of the page with the <body> of the response. It will then use PushState to change the URL to the correct one, preserving refresh semantics and giving you pretty URLs.
The only thing you have to do to enable Turbolinks is have it in your Gemfile, and put //= require turbolinks in your CoffeeScript manifest, which is usually app/assets/javascripts/application.js.

If you want to disable Turbolinks for certain links, add a data-no-turbolink attribute to the tag:
<a href="..." data-no-turbolink>No turbolinks here</a>.
Disable Turbolinks
Turbolinks takes over any local link, sends an AJAX request for the content, and replaces the body on your current page with that content.
In your Gemfile remove: 
gem 'turbolinks' 

Run bundle

In your application.js remove:
//= require turbolinks

In your application.html.erb remove:
  <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

Delete any “data-turbolinks-track” attributes in your your other layouts.





1 comment: