LoginSignup
2
2

More than 3 years have passed since last update.

【Rails6】DEPRECATION WARNING: Single arity template handlers are deprecated. Template handlers must now accept two parameters, the view object and the source for the view object.

Last updated at Posted at 2020-02-03

Rails6アップデート後、rails起動時に以下のWarningを吐くようになってしまったのを調査・解決したメモです。

DEPRECATION WARNING: Single arity template handlers are deprecated. Template handlers must
now accept two parameters, the view object and the source for the view object.
Change:
  >> #<#<Class:0x00007ffbbcf57de0>:0x00007ffbbf219590>.call(template)
To:
  >> #<#<Class:0x00007ffbbcf57de0>:0x00007ffbbf219590>.call(template, source)

TL;DR

$ bundle update slim

で解決。

環境

  • Ruby: 2.6.3
  • Rails: 5.2.4.1 => 6.0.2.1 へアップデート

なんだこのWarning :thinking:

まずはメッセージの内容を見てみます。
template handler 周りのインタフェースに変更が入って、 Single arity template handlers が非推奨になったようです。なるほど、わからん。
https://github.com/rails/rails/blob/v6.0.2.1/actionview/lib/action_view/template/handlers.rb#L46-L56

推奨される修正内容が、

Change:
  >> #<#<Class:0x00007ffbbcf57de0>:0x00007ffbbf219590>.call(template)

ということで、自前のアプリケーションのコードが原因ではなさそう。
どうやら view 周りのGemが怪しそうだぞ、とアタリをつけます。   

slim が怪しい? :thinking:

テンプレートエンジンに slim を使用していたので、 slim の issue を漁ってみます。

image.png

それっぽい雰囲気の issue を発見。しかもClose済み。
https://github.com/slim-template/slim-rails/issues/162

中を見てみると、この issue で報告されているエラー内容とは違う模様でした。
しかし、コメントをサーっと流し見していると、

https://github.com/slim-template/slim-rails/issues/162#issuecomment-530944015
image.png

こんな コメントがあったので、 https://github.com/slim-template/slim/issues/827 も見てみます。

image.png

おーこれこれ。同じWarningだ。
コメントを見ていると、

https://github.com/slim-template/slim/issues/827#issuecomment-478240650
image.png

どうやら、 slim が依存している temple が怪しそう。

ちなみに使用していた temple のバージョンは 0.8.0 でした。

temple が怪しい? :thinking:

同じように temple の issue も漁ってみるとすぐ見つかりました。
https://github.com/judofyr/temple/issues/122
https://github.com/judofyr/temple/pull/121

修正内容を見てみると、おーなるほどね、という感じ。
https://github.com/judofyr/temple/pull/121/files
image.png

すでに修正版がリリース済みなので、
以下のコマンドを実行して slim ごと temple をアップデート。

$ bundle update slim

無事、Warningを解消できました。

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