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">
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…