如何使用Ruby 2.7.0修复Rails的警告消息 [英] How to fix Rails's warning messages with Ruby 2.7.0

查看:347
本文介绍了如何使用Ruby 2.7.0修复Rails的警告消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人用Ruby 2.7.0解决了这个问题吗?

Did anyone resolve this issue with Ruby 2.7.0?

我使用rbenv并安装了Ruby v2.7.0,然后使用Rails v6.0.2.1创建了一个Rails项目.

I used rbenv and installed Ruby v2.7.0 and then created a Rails project using Rails v6.0.2.1.

当前,通过运行以下其中之一

Currently, by running one of

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

服务器已启动并且站点已得到服务,但是在Console日志中,我看到两条警告消息:

the server is up and the site is served but in the Console log I see two warning messages:

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

推荐答案

禁止显示以下警告:

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

现在,只需将RUBYOPT环境变量添加/添加到rails命令中即可:

For now, simply prefix/pass the RUBYOPT environment variable to your rails commands:

RUBYOPT='-W:no-deprecated -W:no-experimental' rails server

RUBYOPT='-W:no-deprecated -W:no-experimental' rails db:migrate

RUBYOPT='-W:no-deprecated -W:no-experimental' rails server
or
RUBYOPT='-W:no-deprecated -W:no-experimental' rails db:migrate

这可能不适用于早期版本的ruby.

This may not work with earlier versions of ruby.

为了与红宝石的早期版本向后兼容,请在其前面加上RUBYOPT='-W0'前缀.

For backward compatibility with earlier versions of ruby prefix it with RUBYOPT='-W0' instead.

示例:

RUBYOPT='-W0' bundle exec rspec

如果您不想在每次运行命令时都添加前缀,只需将其添加到.zshrc.bashrc的最后一行(无论使用什么):

If you don't want to prefix this each time you run a command, then simply add this to the last line of your .zshrc or .bashrc (whatever you're using):

export RUBYOPT='-W:no-deprecated -W:no-experimental'

export RUBYOPT='-W0'

export RUBYOPT='-W:no-deprecated -W:no-experimental'
or
export RUBYOPT='-W0'

另请参阅注释的最后一点:
https://rubyreferences.github.io/rubychanges/2.7.html#warning-和-

Also see last point of the notes here:
https://rubyreferences.github.io/rubychanges/2.7.html#warning-and-

这篇关于如何使用Ruby 2.7.0修复Rails的警告消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆