繁体   English   中英

弃用警告:不推荐使用 alias_method_chain

[英]DEPRECATION WARNING: alias_method_chain is deprecated

我将项目升级到 Rails 5。当我运行rspec我收到一条警告

DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. 
From module, you can access the original method using super. 
(called from <top (required)> at /home/alex/projects/myproject/config/application.rb:13)

application.rb 中的失败行是:

Bundler.require(*Rails.groups)

如何找出导致此弃用警告的原因以及如何消除错误?

安装(除非已经安装)确认并在终端中运行:

ack alias_method_chain /Users/username/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.1/gems/

它将指示使用alias_method_chain所有位置(文件和代码行)。

99% 的几率在您的某些宝石中使用它。

有关您可以做的事情的列表,请参阅我的回答

在 OSX 中,您可以使用:

grep -Ir alias_method_chain `bundle show rails`/..

这将列出所有使用alias_method_chain的 gem

如果 Gemfile 太大,我建议使用the_silver_searcher来搜索已弃用的 alias_method_chain,因为它更快

ag alias_method_chain /path/to/gemset

我有gepgems bash 辅助函数,每次都不会输入 /path/to/gemset

grepgems alias_method_chain

要使用它,请将以下函数添加到您的 .bash_profile(或您喜欢的点文件中的其他位置)

function grepgems() {
  ag $1 $GEM_HOME"/gems"
}

码头工人的解决方案:

docker exec -it [CONTAINER_NAME] /bin/bash

apt-get install silversearcher-ag

ag alias_method_chain $GEM_HOME"/gems"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM