1
0

More than 3 years have passed since last update.

rails g controller 実行時にDeprecation Warningになった。その対処法。

Posted at

結論

Gemfile内の thor のバージョンを 0.19.1に指定した。

背景

 涼しくなってきたのでようやくキーボードを触れるようになった。Railsの個人開発を再開した。rails g controller ... とコントローラーを作ったら、以下のエラー文章が出た。

$rails g controller plans

Running via Spring preloader in process 1645
Deprecation warning: Expected string default value for '--template-engine'; got false (boolean).
This will be rejected in the future unless you explicitly pass the options `check_default_type: false` or call `allow_incompatible_default_type!` in your code
You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.

なんだこれは。一応このメッセージの後にファイルは生成されているようだが、この警告は気になる。少し調べると、海外のサイトがあたった。

Meaning of "Expected string default value for ..." on Ruby on Rails

It has nothing to do with either Rails or Ruby, but was instead caused by the upgrade of the thor gem (which is a dependency of jquery-rails, among others) from 0.19.1 to 0.19.4.

なるほど。thorというGemが関連しているらしい。そういえばrailsガイドにも何か書いてあった。

初めてジェネレータを作成する-Railsガイド

Rails 3.0以降のジェネレータはThorの上に構築されています。Thorは強力な解析オプションと優れたファイル操作APIを提供しています。

rails g はthorの上にあるので、thorがエラーを吐けばこいつもうまく動かなくなるらしい。

もうちょっと探るとGithubのissueにも書いてあった。2017年からあった問題らしい。

Rails generating error after gem update #538

やっていこう

Gemfileに記載しよう。

Gemfile
# rails gのときの Deprecation warning 対策
gem 'thor', '0.19.1'

これだけだとGemfile.lockと異なる!というエラーが出るので、Gemfile.lockの内容を修正する。thorが書いてある行を削除する。

Gemfile.lock
  → 削除    thor (>= 0.20.3, < 2.0)
...
  → 削除    thor (1.1.0)

 あとはbundle update thor を実行した。 

できるようになった。

おわり

よかった。

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