2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Rails]Turbolinksをページごとに無効化する方法

Posted at

環境

ruby 2.6.6
Rails 6.0.3

はじめに

Railsでページ後にTurbolinksを無効化する方法について解説します。

本題

application.html.erbbodyタグの一番上に以下を記述します。

app/views/layouts/application.html.erb
# ここから追加
<div 
  <% if content_for?(:body_attributes) %>
    <%= yield(:body_attributes) %>
  <% end %>
>
# ここまで

<%= render "layouts/header" %>
  <%= yield %>
<%= render "layouts/footer" %>

#閉じタグも忘れずに
</div> 

パーシャルを使ってる場合はしっかりとdivタグの下に記述してください

次にTurbolinksを無効化したいviewに下記を追加します。

例(top.html.erb)
<% content_for(:body_attributes) do %>
    data-turbolinks="false"
<% end %>

以上で実装できます。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?