[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
[Rails] How to use authenticate_user!
[Rails] How to implement scraping
[Rails] How to make seed
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to use Scope
[Introduction to Rails] How to use render
How to install Swiper in Rails
How to implement image posting using rails
[Rails] How to use video_tag to display videos
[Rails] How to use helper method, confimartion
How to use credentials.yml.enc introduced in Rails 5.2
[Rails] How to translate devise into Japanese
How to build Rails 6 environment with Docker
[Rails] How to build an environment with Docker
[Rails] How to get success and error messages
Rails "How to delete NO FILE migration files"
[Rails] How to use PostgreSQL in Vagrant environment
[Rails] How to convert UC time display to Japanese time display
How to use identity
How to install MySQL
How to write migrationfile
How to build android-midi-lib
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
How to type backslash \
How to concatenate strings
[Ruby on Rails] How to change the column name
How to query Array in jsonb with Rails + postgres
[Rails] How to load JavaScript in a specific view
(Ruby on Rails6) How to create models and tables
[Rails] How to display an image in the view
Java --How to make JTable
Pass parameters to Rails link_to
[iOS] How to read Carthage
How to check JSF version
How to handle an instance
How to convert Java radix
How to use GC Viewer
How to run React and Rails on the same server
[Java] How to implement multithreading
[Rails 5] How to use gem gon ~ How to pass variables from Rails to JS ~
How to use Lombok now
How to install JDK8-10 (Mac)
How to initialize Java array
How to insert a video
How to create a method
How to rollback migration files
[Creating] How to use JUnit
[Rails] How to display information stored in the database in view
[Rails] How to write user_id (foreign key) in strong parameter
Introduced gRPC client to rails
How to authorize using graphql-ruby
[Ruby on Rails] How to avoid creating unnecessary routes for devise
[Rails 5] How to display the password change screen when using devise
[rails6.0.0] How to save images using Active Storage in wizard format