mbleigh/acts-as-taggable-on — Issue #208: Using ownership .tag() method causes unwanted save on object being tagged.
Author: zorn
Created: 2011-12-13 00:30:34+00:00
State: open

So in my current Rails project we're using acts-as-taggable-on.

https://github.com/mbleigh/acts-as-taggable-on

There are many accounts in the system and each account has many events.

Event is the parent object for a bunch of other things like sessions_descriptions and venues. These things can be tagged and the tags need to be owned by the event so as to not bleed over into another event's tag cloud.

acts-as-taggable-on has support for this. From it's readme some sample code:

class User < ActiveRecord::Base
acts_as_tagger
end

class Photo < ActiveRecord::Base
acts_as_taggable_on :locations
end

@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations)

The problem I'm experiencing is that when I call a method like this it is causing a .save method to be called on @some_photo. This screws me over since I'd pref to keep track of a transient string to manage the human editable tag list and execute the official tagging after_save -- but if doing the official tagging in after_save causes a save I end up with a execution loop and crash Ruby (or throw a more friendly exception on Ruby 1.9.3).

I don't think observers would help me since they sit atop the save callbacks too.

I feel like this is a bug in acts-as-taggable-on (in that using the .tag() method causes a side effect .save to be called on the passed in attributes but I'm hopeful to work around it if I can cause there don't seem to be alot of other tagging modules being actively worked on and I'd pref not to write my own.

Any feedback or suggestions welcome.