Thursday, December 17, 2009

DEPRECATION WARNING: require "activesupport" is deprecated and will be removed in Rails 3

You might see this from time to time. Here's the ActiveRecord variant:

DEPRECATION WARNING: require "activerecord" is deprecated and will be removed in Rails 3. Use require "active_record" instead.. (called from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/activerecord.rb:2)

For instance, in context:

<imac of doom:gilesgoatboy> [12-17 09:27]
↪ ruby helpers/browsers_helper_test.rb
DEPRECATION WARNING: require "activerecord" is deprecated and will be removed in Rails 3. Use require "active_record" instead.. (called from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/activerecord.rb:2)
Loaded suite helpers/browsers_helper_test
Started

Finished in 0.000193 seconds.

0 tests, 0 assertions, 0 failures, 0 errors


The culprit's easy to find, partly because I highlighted it. /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/activerecord.rb:2 means line 2 of /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/activerecord.rb. So you open up that file with sudo and comment out line 2.

1 require 'active_record'
2 # ActiveSupport::Deprecation.warn 'require "activerecord" is deprecated and will be removed in Rails 3. Use require "active_record" instead.'


You need to do this with ActiveSupport too - in fact, until I do some hacking, this is the only way to use my password gem without ActiveSupport driving you crazy (assuming you're a neat freak). In my opinion this is overzealous - if you, in your external code, do the right thing and require 'active_support', you still see a message warning you to require 'active_support'. You also can't disable it with ruby -W0, the way you can with regular Ruby warnings. However, it's very easy to fix, and it definitely gets the message out.

By the way, if you're wondering why on earth I have my Ruby gems in /opt/local, even though it's 2009, it's not actually my machine, and I'm going to fix that at some point. Likewise, my password gem predates 1password, which is probably a superior option today. However, it's just an example; any Ruby file which uses ActiveSupport as a gem (as opposed to via rip) will encounter the same phenomena.