Silencing Deprecation warnings in Rails 3
Solution 1
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.
Solution 2
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!
Solution 3
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
Related videos on Youtube
oligan
In part of my spare time, I work on fun programming projects. One was trying to analyze what underlies Wikipedia's Get to Philosophy game. I also worked on one called the "Small Eigen Collider". I'm currently learning Japanese, and I'm an active participant in lang-8.com, a website where you write journal entries in a language you're learning, and get corrected by native speakers of that language. In return, you correct people writing entries in your native language. Recently, I've been asking a few questions prompted by slightly incorrect English I've encountered on lang-8.
Updated on January 02, 2020Comments
-
oligan over 4 years
Can anyone tell me how to silence deprecation warinings in Rails 3?
I have a few situations where it is throwing false positives. Namely using - for loops in haml and f.error_messages from the dynamic_form plugin.
Thanks
-
mikej about 14 yearsDo you want to silence all deprecation warnings or just warnings in selected blocks of code?
-
Admin about 14 yearspreferably just the pieces of code i know are safe, but either way if i could toggle it would be nice just to cut out some log noise.
-
-
Michael Durrant over 10 yearsI also have some great black duct tape you can put over your engine oil light ;)
-
Chris Hough over 10 yearsthank you for posting, compared to the other solutions, this is the only thing that worked in Rails 4