Thursday, February 14, 2008

Ruby acts_as_taggable plugin bug fix for Rails 2.0.2

What?
I'm working on a small rails app and wanted tags, so I went ahead and installed the acts_as_taggable plugin. However, I had some problem with installation. First, I just ran

./script/plugin install acts_as_taggable

and followed setup procedures. However, I then got the following error when I called acts_as_taggable in my class

NameError: uninitialized constant Tag

I then found a post that directed me to the correct source for the tag:

./script/plugin install http://svn.rubyonrails.org/rails/plugins/legacy/acts_as_taggable/

However, running rails 2.0.2, the has_many API has changed, so I got the following error:

ArgumentError (The :dependent option expects either :destroy, :delete_all, or :nullify (true))

I traced the error down in the plugin to the file rails_root/vendor/plugins/acts_as_taggable/lib/acts_as_taggable.rb

The error is on line 18

has_many :taggings, :as => :taggable, :dependent => true

should be

has_many :taggings, :as => :taggable, :dependent => :destroy

Now it works!

6 comments:

Anonymous said...

Very helpful,
Thanks.

Anonymous said...

Thanks. Saw your response to my RubyForge post. I'll try it out.

chamnap said...

I got another error in the gem file taggable.rb. It uses push_with_attributes method on line 577 which is depreciated on rails 2.0. Then I changed it to <<. It works. What do you think?

Marcus Westin said...

Hey Chamnap,

acts_as_taggable has three files: acts_as_taggable.rb, tag.rb and tagging.rb. None of these have more than 100 lines, and I can't find a call to push_with_attributes.

Are we talking about the same plugin?

chamnap said...

I found in this gem has only 1 file "taggable.rb". Which version of your acts_as_taggable do you use? I have installed it on my server since rails 1.2.3. Most importantly, it has only one file called "taggable.rb". Maybe I need to reinstall it.

Marcus Westin said...

Ah, right - this is the plugin, not the gem. Unfortunate naming :)