由gem生成的沉默弃用警告

时间:2017-01-20 08:20:41

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

我在Rails 5.0.0.1应用程序中使用unscoped_associations gem。

我收到此弃用警告:

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/rhl/myapp/config/application.rb:8)
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/rhl/myapp/config/application.rb:8)
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/rhl/myapp/config/application.rb:8)

如何在生产环境中消除此警告?

我尝试过添加:

config.active_support.deprecation = :silence
production.rb

中的

但它没有用。

2 个答案:

答案 0 :(得分:11)

ActiveSupport::Deprecation.silenced = true

答案 1 :(得分:3)

根据文档http://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Behavior.html

  

设置行为只会影响启动后发生的弃用。宝石引发的弃用警告不受此设置的影响,因为它们发生在Rails启动之前。

然而,我确实发现,如果您在之前将设置为需要的宝石,它将会使警告静音。

例如,请放置以下行:

ActiveSupport::Deprecation.behavior = :silence

Bundler.require(*Rails.groups)

它应该使宝石警告静音。