由gem生成的沉默弃用警告

web*_*ter 6 ruby ruby-on-rails 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)
Run Code Online (Sandbox Code Playgroud)

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

我试过添加:

config.active_support.deprecation = :silence
Run Code Online (Sandbox Code Playgroud)

production.rb

但它不起作用.

小智 11

ActiveSupport::Deprecation.silenced = true


Luk*_*und 5

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

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

但是,我确实发现,如果您需要宝石之前设置它,它将使警告静音。

例如,放置这一行:

ActiveSupport::Deprecation.behavior = :silence
Run Code Online (Sandbox Code Playgroud)

Bundler.require(*Rails.groups)
Run Code Online (Sandbox Code Playgroud)

它应该使 gem 警告静音。

  • 这将不起作用,因为在此之前 gem 已初始化。这对 gems 没有影响,但会影响 rails 的特定警告 (4认同)
  • 我已经尝试过你的答案。我仍然收到相同的弃用警告。 (2认同)