gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:31:18 25 4
gpt4 key购买 nike

有人用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com