Including gems with new rubygems

Have You seen something like this:


NameError (undefined local variable or method `acts_as_taggable' for Route:Class):

after You have upgraded to rubygems-0.9.2? Well I saw and did a little investigation. The results:

With new rubygems require_gem is replaced with gem command. One of the differences is that with gem autorequire feature is no longer enabled. In other words gem prepares LOAD_PATH with directory with gems code, but does not include gems code automagically. So with gem command including acts_as_taggable should look like this:

gem 'acts_as_taggable'
require 'taggable'

As You can see we need to specify directly file with gem code (but we don’t have know what path is needed). The question is what we need to include. Well, this information we can get from gem itself, using shell gem command (following block is shell CLI not Ruby code):

[viciu@bsd ~]$ gem spec acts_as_taggable| grep autoreq                      
autorequire: taggable

This way we know what we have to include to run gem.

One thought on “Including gems with new rubygems

  1. Nice work. The whole tagging thing in Rails is whacky to me still. Which shall I use, the gem that everyone says is depricated, the plugin which I can\’t seem to find a decent api for, acts_as_taggable_on_steroids which has the same problem. I\’m working with the gem right now cause its the only one I found a decent api for.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.