Search code examples
ruby-on-rails-3modelacts-as-taggable-on

Rails - ActsAsTaggableOn gem - tagging for more models?


I am playing with the awesome ActsAsTaggableOn gem and now I am facing with the question, how to have more than one tagged "systems" in one app.

For example, currently I am using already tagging for my articles - I stepted by the tutorial on GitHub and the gem created the tables taggings and tags.

How can I add tagging also for photos (I would like to have separate tables for photo-tags)?


Solution

  • The gem really doesn't support separate tables for tags on different sorts of taggables, but there's really no reason to do that that I can think of. It has one taggings table and one tags table, but taggings is polymorphic, so all you need to do is add acts_as_taggable to your Photo class.

    If you need to fetch some info about taggings only on one type, you can add some conditions to the relevant query - .where('taggings.taggable_type = ?', 'Photo'), or similar.