0
0

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.

ページごとにturbolinksをON/OFFする【Rails】

Last updated at Posted at 2021-08-21

問題

CSSフレームワークを使ってたり、JSによるDOM操作がCSSに依存するようなコードを書いてるとturbolinksのせいでレイアウトがステートレスじゃなくなってバグる。

解決策

headタグ内に

applictaion.html.haml
%meta{name: "turbolinks-visit-control", content: "reload"}

を追加するとフルリロードされ、window.onload, turbolinks:load'も両方発火する。

これをページ毎に設定するには

applictaion.html.haml
- pages = {"users"=> ["new", "edit"], "items"=> ["new"]}
- if pages.map {|c, a| true if (c == contoller.conroller_name && a.include?(controller.action_name))}.include?(true)
  %meta{name: "turbolinks-visit-control", content: "reload"}

のようにすればいい。

アクションだけなら

- if ["new", "edit"].include?(controller.action_name)

またはcontent_for?を使う。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?