Rails 4: disable Turbolinks in a specific page
Here's a cleaner solution:
In /app/views/layouts/application.html.erb
, replace the <body>
tag with this:
<body
<% if content_for?(:body_attributes) %>
<%= yield(:body_attributes) %>
<% end %>>
Now, if you want to disable turbolinks in a particular view, e.g. /app/views/home/index.html.erb
, you can add this to the file:
for Rails 4
<% content_for(:body_attributes) do %>
data-no-turbolink="true"
<% end %>
and that will end up rendering as:
<body data-no-turbolink="true">
for Rails 5
In Rails 5, the syntax is slightly different:
<% content_for(:body_attributes) do %>
data-turbolinks="false"
<% end %>
and that will end up rendering as:
<body data-turbolinks="false">
Add “data-no-turbolink” to the <body> tag
of the the page you want it disabled on
If you have a shared layout file which i am assuming you do, you can do an if statement and check the params[:controller] and params[:action] and just add it to the one area
Edited Jan 2021: As pointed out by @weltschmerz under rails 5 data-turbolinks="false"
is the preference.