【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.


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

まずはメッセージの内容を見てみます。
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 が怪しい?

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

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

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

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

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

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

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

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

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

temple が怪しい?

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

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

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

$ bundle update slim

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