Suggestions on how to track tag count for a particular object

Posted by Robin Fisher on Stack Overflow See other posts from Stack Overflow or by Robin Fisher
Published on 2010-06-09T14:39:20Z Indexed on 2010/06/09 14:42 UTC
Read the original article Hit count: 262

Hi,

I'm looking for suggestions on how to track the number of tags associated with a particular object in Rails. I'm using acts_as_taggable_on and it's working fine. What I would like to be able to do is search for all objects that have no tags, preferably through a scope i.e. Object.untagged.all

My first thought was to use an after_save callback to update an attribute called "taggings_count" in my model:

def update_taggings_count
  self.taggings_count = self.tag_list.size
  self.save
end

Unfortunately, this does the obvious thing of putting me in an infinite loop. I need to use an after_save callback because the tag_list is not updated until the main object is saved.

Would appreciate any suggestions as I'm on the verge of rolling my own tagging system.

Regards

Robin

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about polymorphic-associations