[Java] [Rails] how to disable the turbolinks

less than 1 minute read

Development environment

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

How to completely disable

Disable 1.Gem

Gemfile


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

terminal


$ bundle update

Edit the 2.application.js

Delete the =.

application.js


// Change before
//= require turbolinks

// after change
// require turbolinks

3. Edit application.html.slim

Remove 'data-turbolinks-track':'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 disabled

How to edit the ### 1.JavaScript

** ① ~ case of .js file **

$(document).on('turbolinks:load', function() {
  Processing you want to disable the // turbolinks
});

** ② ~ case of .coffee file **

```Coffeescript: ~ .coffee $ (Document) .on ‘turbolinks: load’, -> Processing you want to disable the # turbolinks


### 2. How to edit a link

** ①link_to ** If you want to add an attribute to the

```slim:~html.slim
= Link_to '', root_path, 'data-turbolinks': false

** When surrounded by ②div **

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