Ruby 2.7.0 で Rails の警告メッセージを修正する方法 質問する

Ruby 2.7.0 で Rails の警告メッセージを修正する方法 質問する

誰かこの問題を解決しましたかRuby 2.7.0?

Ruby v2.7.0 を使用しrbenvてインストールし、 を使用して Rails プロジェクトを作成しましたRails v6.0.2.1

現在、

rails s
rails s -u puma
rails s -u webrick

サーバーは起動しており、サイトは提供されていますが、Consoleログには 2 つの警告メッセージが表示されます。

local:~/rcode/rb27$ rails s
=> Booting Puma
=> Rails 6.0.2.1 application starting in development 
=> Run `rails server --help` for more startup options
.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here
Puma starting in single mode...
* Version 4.3.1 (ruby 2.7.0-p0), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000 

したがって、警告メッセージは次のようになります。

**.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call**

**.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here**

私が見たこのリンクまた、「非推奨の警告を無効にしたい場合は、コマンドライン引数 -W:no-deprecated を使用するか、コードに Warning[:deprecated] = false を追加してください」などの警告を切り替えるための提案もありますが、アクションパック v6.0.2.1 ではもう少し良い解決策/修正を考えていました。

ベストアンサー1

次のような警告を抑制するには:

warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call

RUBYOPT今のところは、環境変数を Rails コマンドの前に付ける/渡すだけです。

RUBYOPT='-W:no-deprecated -W:no-experimental' rails server
または
RUBYOPT='-W:no-deprecated -W:no-experimental' rails db:migrate

これは、以前のバージョンの Ruby では動作しない可能性があります。

以前のバージョンの Ruby との下位互換性を保つには、RUBYOPT='-W0'代わりに をプレフィックスとして付けます。

例:

RUBYOPT='-W0' bundle exec rspec

コマンドを実行するたびにプレフィックスを付けたくない場合は、.zshrcまたは.bashrc(使用しているもの) の最後の行にこれを追加するだけです。

export RUBYOPT='-W:no-deprecated -W:no-experimental'
または
export RUBYOPT='-W0'

ここでのメモの最後のポイントも参照してください:
https://rubyreferences.github.io/rubychanges/2.7.html#warning-and-

おすすめ記事