15

I am using the unscoped_associations gem in my Rails 5.0.0.1 application.

I am getting this deprecation warning:

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)

How can I silence this warning in production environment?

I have tried adding:

config.active_support.deprecation = :silence

in production.rb

But it's not working.

Community
  • 1
  • 1
webster
  • 3,902
  • 6
  • 37
  • 59
  • This one worked: https://stackoverflow.com/questions/5591509/suppress-ruby-warnings-when-running-specs (export RUBYOPT=-W0) – Glenn Mar 02 '21 at 20:39

3 Answers3

13

ActiveSupport::Deprecation.silenced = true

Nos4a2
  • 162
  • 4
  • 1
    This doesn't appear to work anymore for a gem I'm using (numo-narray). Tried this line in a variety of places, with no success. Lukas's answer doesn't work either. – Glenn Mar 02 '21 at 20:27
  • 1
    This doesn't work – jedi Dec 09 '21 at 14:48
7

Per the documentation http://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Behavior.html:

Setting behaviors only affects deprecations that happen after boot time. Deprecation warnings raised by gems are not affected by this setting because they happen before Rails boots up.

I did find, however, that if you set it before your gems are required, it will silence warnings.

For example, place this line:

ActiveSupport::Deprecation.behavior = :silence

before

Bundler.require(*Rails.groups)

and it should silence the gem warnings.

Lukas Eklund
  • 6,068
  • 1
  • 32
  • 33
1

It's better to silence only the part you don't control or cannot easily fix:

ActiveSupport::Deprecation.silence do     
  ActiveSupport::Deprecation.warn('something broke!')
end
# => nil

If it's inside the gem as in your case you can disable require in Gemfile and require that gem in initializers wrapped by silencer above.

Lev Lukomsky
  • 6,346
  • 4
  • 34
  • 24