This post originated from an RSS feed registered with Ruby Buzz
by rwdaigle.
Original Post: How to Turn Deprecation Warnings Off in Rails
Feed Title: Ryan's Scraps
Feed URL: http://feeds.feedburner.com/RyansScraps
Feed Description: Ryan Daigle's various technically inclined rants along w/ the "What's new in Edge Rails" series.
I was talking with a friend of mine last week about the new Rails deprecation warnings that you’ll see when you do naughty things like access @cookies from your controller or use deprecated methods like ActiveRecord’s find_all. Sometimes it’s useful to turn off those warnings – especially when they’re coming from a part of your application you don’t control (i.e. a third-party library).
To turn off all deprecation warnings, just do the following:
ActiveSupport::Deprecation.silenced = true
Or, if you want to perform something other than spit out deprecation warnings you can re-route them however you want within a block:
Or, if you want to be more granular, you can silence specific parts of your code that you know reference deprecated code:
def bad_action
ActiveSupport::Deprecation.silence { p "Referencing #{@cookies} is bad" }
end
Hopefully this will get you past any annoying deprecations you can’t do much about (without giving you an easy out for those that you can do something about).