【问题标题】:DEPRECATION WARNING: alias_method_chain is deprecated弃用警告:不推荐使用 alias_method_chain
【发布时间】:2016-10-21 09:58:42
【问题描述】:

我将项目升级到 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)

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

【问题讨论】:

    标签: ruby-on-rails ruby rspec ruby-on-rails-5


    【解决方案1】:

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

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

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

    99% 的机会在您的某些宝石中使用它。

    请参阅my answer,了解您可以采取的措施。

    【讨论】:

    • @AlexanderShmatko 确保提供当前 gems 目录的正确路径 :)
    • 如果有人想通过CPAN安装上面提到的ack,这里有一个很棒的新手教程egoleo.wordpress.com/2008/05/19/…
    • 或使用 ag 而不是 ack - 相同,但更快
    【解决方案2】:

    在 OSX 中,您可以使用:

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

    这将列出所有使用alias_method_chain的宝石

    【讨论】:

      【解决方案3】:

      如果 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"
      }
      

      【讨论】:

        【解决方案4】:

        docker 解决方案:

        docker exec -it [CONTAINER_NAME] /bin/bash

        apt-get install silversearcher-ag

        ag alias_method_chain $GEM_HOME"/gems"

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-05-10
          • 1970-01-01
          • 2021-08-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-01-31
          • 1970-01-01
          相关资源
          最近更新 更多