Rails: How to disable turbolinks in Rails 5?

Ruby on-Rails-5

Ruby on-Rails-5 Problem Overview


It's a constant headache when dealing with websockets, and it kills my performance in addition to adding bugs. Since ActionCable is the whole reason I upgraded I'd very much like to get rid of it completely.

Ruby on-Rails-5 Solutions


Solution 1 - Ruby on-Rails-5

Basically straight from here. It's for Rails 4, but I believe the steps are the same.

  1. Remove the gem 'turbolinks' line from your Gemfile.

  2. Remove the //= require turbolinks from your app/assets/javascripts/application.js .

  3. Remove the two "data-turbolinks-track" => true hash key/value pairs from your app/views/layouts/application.html.erb .

Edit: As of at least Rails 5.0.0 the last step should refer to "data-turbolinks-track" => "reload" as opposed to "data-turbolinks-track" => true. Thanks to @boddhisattva

Edit: As of at least Rails 4.2 you can generate a project without turbolinks to begin with. Just use something like this:

rails new my_app --skip-turbolinks

Solution 2 - Ruby on-Rails-5

Removing //= require turbolinks from app/assets/javascripts/application.js seems to have done the trick.

I also removed both turbolinks references in app/views/layouts/application.html.erb

Solution 3 - Ruby on-Rails-5

If you are using Webpacker (Rails 5-6)

  • Delete this line from Gemfile and run bundle:

gem 'turbolinks', '~> 5'

  • Run yarn remove turbolinks

  • Delete this line from application pack file app/javascript/packs/application.js:

    require("turbolinks").start()

  • Remove any data-turbolinks data attributes from your html.

Change:

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

to

<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_pack_tag 'application' %>

Solution 4 - Ruby on-Rails-5

you can also do it when you create your rails application by using;

rails new app name --skip-turbolinks

Solution 5 - Ruby on-Rails-5

Completely removing the turbolinks tags from application.html.erb might break CSS and JS. add this lines instead of the turbolinks if no CSS or JS is loaded:

<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGlyphGryphView Question on Stackoverflow
Solution 1 - Ruby on-Rails-5arjabbarView Answer on Stackoverflow
Solution 2 - Ruby on-Rails-5GlyphGryphView Answer on Stackoverflow
Solution 3 - Ruby on-Rails-5lunrView Answer on Stackoverflow
Solution 4 - Ruby on-Rails-5DannyView Answer on Stackoverflow
Solution 5 - Ruby on-Rails-5Ben LeviView Answer on Stackoverflow