【问题标题】:Silence deprecation warning generated from of a gem从 gem 生成的静默弃用警告
【发布时间】:2017-01-20 08:20:41
【问题描述】:

我在我的 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

但它不起作用。

【问题讨论】:

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


【解决方案1】:

ActiveSupport::Deprecation.silenced = true

【讨论】:

  • 这似乎不再适用于我正在使用的 gem (numo-narray)。这条线路在很多地方都试过了,都没有成功。卢卡斯的回答也不管用。
  • 这不起作用
【解决方案2】:

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

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

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

例如,放置这一行:

ActiveSupport::Deprecation.behavior = :silence

之前

Bundler.require(*Rails.groups)

它应该使 gem 警告静音。

【讨论】:

  • 我已经试过你的答案了。我仍然收到相同的弃用警告。
  • stackoverflow.com/a/41820913/3185510 工作。感谢您的帮助!
  • 这不起作用,因为在此之前已初始化 gem。这对 gem 没有影响,但会对特定于 rails 的警告产生影响
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多