Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Akilah Jones
Akilah Jones
18,397 Points

Rails: How do I suppress deprecation warnings?

How can I suppress the deprecation warning messages?

I've tried commenting out the deprecation entries under config/environments/test.rb and config/environments/development.rb

Note: I'm currently taking "Build a Todo List Application with Rails 4"

Can you please specify which deprecation warning is bugging you?

2 Answers

Ryan Vermotoen
Ryan Vermotoen
4,262 Points

There are two parts to this answer, one you're looking for and possibly one you're not:

The answer you're looking for: To turn off depreciation warnings, simply set

ActiveSupport::Deprecation.silenced = true

You can also turn off warnings for specific code, with

ActiveSupport::Deprecation.silence do your_code_here end

The answer you're possibly not:

There is a reason you're getting these warnings, its because soon the way that you are writing your code won't work, this is an issue, instead of hiding the warnings I recommend upgrading the gem in question and learning what syntax they want you to use in the new version and start using it. Rails changes a fair amount, so with pretty much all tutorials you watch, unless they are made last month or something, are going to be somewhat outdated (at least with tiny syntax stuff).

So again, I would recommend doing something about the warning instead of hiding it.

Akilah Jones
Akilah Jones
18,397 Points

You're absolutely right....

The warning message was just so "massive and overwhelming", at the moment, that I thought it'd be easier to suppress it for now and figure it out later. But, it's best to just figure it out now. Resolving things like this is an important part of the learning process.

Thanks for putting me back on track, Ryan

AJ

Zeth Odderskov
PLUS
Zeth Odderskov
Courses Plus Student 38 Points

Where do I write

ActiveSupport::Deprecation.silenced = true

? In the controller? In each file?

I'm getting these warnings:

/Users/MYUSER/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
/Users/MYUSER/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
/Users/MYUSER/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.1/lib/active_support/core_ext/numeric/conversions.rb:138: warning: constant ::Fixnum is deprecated

I'm not using either Fixnum or Bignum anywhere. I read here that it was because I was using ruby-version 2.4.0 - but that link doesn't suggest another solution instead of 'sit tight'. But I don't want to sit tight while I drown in warnings. I want to hide them! :-)