views:

2469

answers:

4

Everytime I run rake or most rails commands, I get an annoying warning. I'm still a beginner with Ruby/Rails, and I would like advice on how to hack boot.rb to stop the annoying warning. I'm using Rails 1.2.6 and RubyGems 1.3.1. (I haven't upgraded Rails to 2.x because I'm still learning Rails from a book that uses 1.2.x.) I'm grateful for any advice. I've been unable to find a solution through googling. Thanks!

boot.rb line 20:

rails_gem = Gem.cache.search('rails', "=#{rails_gem_version}.0").sort_by { |g| g.version.version }.last

Annoying message:

boot.rb:20:Warning: Gem::SourceIndex#search support for String patterns is deprecated
A: 

First, you should investigate an approach that would remove the warning (like upgrading rails or ruby-gems), rather than suppressing if possible. Second, according to the docs on the warn method ( http://www.ruby-doc.org/core/classes/Kernel.html#M006017 ) you can suppress it by invoking /usr/bin/ruby with the -W0 flag. Also note that this message is outputed on STDERR, so you could use the normal unix redirection techniques as well (for instance to redirect it to /dev/null or even better a warnings.log file)

diclophis
-1 -- Did not address the point of the question in any helpful way. The idea of suppressing all warnings is not a good one. And the idea of upgrading was clearly addressed by the OP.
Larry K
i'm going to bump it because diclophis does want to fix the underlying error (old rails)
Shaun F
+7  A: 

There is a call to Gem Source Index in a boot.rb: "Gem.cache.search", just replace "search" with "find_name".

Seems to work great, thanks! Now I can continue working on the depot app from the Dave Thomas/DHH book on Rails without being annoyed everytime I execute rake.
barneytron
A: 

at: Alexandr

Thank you. I have had the same problem and your answer was spot on. Now I can continue with learning from the book without encountering error messages not covered in the text. Thanks!

A: 

The answer keeps on giving. Thanks. It was driving me nuts.

With respect to updates to newer versions, the book, (Agile Development) fails with newer versions.

Also, I am frequently doing rake db:migrate. I don't know how to stifle the message by calling ruby -W0 in that case.

Paul Campbell

related questions