[Rails] How to disable turbolinks

Development environment

・ Ruby: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ OS: macOS Catalina

How to disable it completely

1. Disable Gem

Gemfile


#Comment out
# gem 'turbolinks', '~> 5'

Terminal


$ bundle update

2. Edit ʻapplication.js`

Delete =.

application.js


//Change before
//= require turbolinks 

//After change
// require turbolinks 

3. Edit ʻapplication.html.slim`

'data-turbolinks-track': Remove'reload'.

slim:application.html.slim


/Change before
= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload'
= javascript_include_tag 'application', 'data-turbolinks-track': 'reload'

/After change
= stylesheet_link_tag    'application', media: 'all'
= javascript_include_tag 'application'

How to partially disable

1. How to edit JavaScript

** ① For ~ .js files **

~.js


$(document).on('turbolinks:load', function() {
  //Processing that wants to disable turbolinks
});

** ② For ~ .coffee files **

~.coffee


$(document).on 'turbolinks:load', -> 
  #Processing that wants to disable turbolinks

2. How to edit a link

** ① When adding an attribute to link_to **

~html.slim


= link_to '', root_path, 'data-turbolinks': false

** ② When enclosing with a div **

~html.slim


div data-turbolinks='false'
  = link_to '', root_path

Recommended Posts

[Rails] How to disable turbolinks
How to write Rails
Disable turbolinks in Rails
How to uninstall Rails
[rails] How to post images
[Rails] How to use enum
[Rails] How to install devise
[Rails] How to use enum
How to read rails routes
How to use rails join
How to write Rails validation
[Rails] How to use validation
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping
[Rails] How to make seed
How to write Rails routing
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to use Scope
[Rails] How to use gem "devise"
How to deploy jQuery on Rails
[Rails] How to install Font Awesome
[Rails] How to use devise (Note)
[Rails] How to use flash messages
[rails] How to display db information
[Rails] How to write in Japanese
[Rails] How to prevent screen transition
How to use Ruby on Rails
How to deploy Bootstrap on Rails
[Rails] How to speed up docker-compose
[Rails] How to add new pages
Rails on Tiles (how to write)
[Rails] How to write exception handling?
[Rails] How to install ImageMagick (RMajick)
[Rails] How to install Font Awesome
[Rails] How to use Active Storage
How to introduce jQuery in Rails 6
[Rails] How to implement star rating
How to return Rails API mode to Rails
How to get along with Rails
[Introduction to Rails] How to use render
How to install Swiper in Rails
How to implement search functionality in Rails
How to use custom helpers in rails
[Rails] How to convert from erb to haml
[Rails] How to upload images using Carrierwave
[Rails] How to use rails console with docker
How to insert a video in Rails
[Rails] How to use ActiveRecord :: Bitemporal (BiTemporalDataModel)
[Rails] How to use the map method
How to deploy
How to use MySQL in Rails tutorial
How to resolve errors when installing Rails 5.1.3
[rails] How to configure routing in resources
[Ruby on Rails] How to use redirect_to
[rails] How to create a partial template
[Rails 5.x] How to introduce free fonts
How to implement ranking functionality in Rails
[Note] How to use Rails 6 Devise + cancancan
[Ruby on Rails] How to use kaminari