Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silencing Deprecation warnings in Rails 3

People also ask

How do I turn off deprecated warnings?

When nothing else works: $ pip install shutup . Then at the top of the code import shutup;shutup. please() . This will disable all warnings.

What are deprecated warnings?

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 remove deprecated in Java?

The javac -Xlint:removal option is enabled by default, so removal warnings are shown. The warnings can also be turned off independently (note the "–"): -Xlint:-deprecation and -Xlint:-removal . This is an example of an ordinary deprecation warning.


To silence all deprecation warnings you can do:

ActiveSupport::Deprecation.silenced = true

This could be placed in an initializer or in the environment file for a specific environment (e.g. to silence only in production for example.)

Or for a specific section of code, enclose it in a block:

ActiveSupport::Deprecation.silence do
  # no warnings for any use of deprecated methods here
end

This works for both Rails 3 & 4.


The accepted answer didn't work for me with Rails 3.2.12. Placing it in either the environments/production.rb or an initializer still outputted the warnings. I had to put it in my config/environment.rb file before the application was initialized:

# Load the rails application
require File.expand_path('../application', __FILE__)

::ActiveSupport::Deprecation.silenced = true if Rails.env.production?

# Initialize the rails application
Notices::Application.initialize!

Ryan Daigle wrote an article about this, in which he also showed how you can intercept the deprecation warning and do something else with it, like send it to a log file:

ActiveSupport::Deprecation.behavior = Proc.new { |msg, stack| MyLogger.warn(msg) }

http://ryandaigle.com/articles/2006/12/4/how-to-turn-deprecation-warnings-off-in-rails