Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silence deprecation warning generated from of a gem

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.

like image 514
webster Avatar asked Jan 20 '17 08:01

webster


People also ask

How do you stop a deprecated warning?

Place the @SuppressWarnings annotation at the declaration of the class, method, field, or local variable that uses a deprecated API. The @SuppressWarnings options are: @SuppressWarnings("deprecation") — Suppresses only the ordinary deprecation warnings.

What is a deprecation warning?

Deprecation warnings are a common thing in our industry. They are warnings that notify us that a specific feature (e.g. a method) will be removed soon (usually in the next minor or major version) and should be replaced with something else.

How do you silence a ruby warning?

The TL;DR is that you need to use RUBYOPT='-W:no-deprecated -W:no-experimental' to disable the deprecations. This will also disable experimental feature warnings as well.

Is Ruby deprecated?

With the release of Dart Sass 1.0. 0 stable last week, Ruby Sass was officially deprecated.


2 Answers

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.

like image 196
Lukas Eklund Avatar answered Oct 31 '22 01:10

Lukas Eklund


ActiveSupport::Deprecation.silenced = true

like image 40
Nos4a2 Avatar answered Oct 31 '22 02:10

Nos4a2