ruby-on-rails - 如何使用 Ruby 2.7.0 修复 Rails 的警告消息

标签 ruby-on-rails ruby warnings ruby-on-rails-6 ruby-2.7

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

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

目前,通过运行其中之一

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

服务器已启动并且站点已提供服务,但在 Console 中日志我看到两条警告消息:
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 命令的环境变量:
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-

关于ruby-on-rails - 如何使用 Ruby 2.7.0 修复 Rails 的警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59491848/

相关文章:

ruby-on-rails - Shopify如何确保其液体模板安全(避免使用XSS)?

ruby - Controller 无法检测到 ajax 请求

ruby-on-rails - 我如何邀请用户(使用 devise_invitable)并在邀请过程中填充其他字段?

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

java - 对象到泛型类型转换的未检查警告的定义在哪里?

ruby-on-rails - Ruby,动态查询事件模型

ruby-on-rails - 您将 Rails 应用程序放在服务器上的什么位置?你用什么用户部署?

c++ - 背后的原因:尽管按名称返回,本地变量 'derived'仍将被复制

ruby-on-rails - 如何通过 Graph API 将应用程序添加到页面? (配考拉 gem )

ruby-on-rails - Rails : making link_to method send remote request as JSON type, 不是 JS 类型