3
votes

Most Rails tagging gems support tagging an object with arbitrary strings. (In addition to this) I'd like to tag an object with other objects.

Imagine I am building a Q&A site for Dog Lovers: I want a person to be able to ask a question. The person can then tag that question with arbitrary strings (as every tagging gem supports), BUT if the question is about a particular dog breed or dog breed(s), I'd like the user to additionally be able to tag the question with dog breeds. Dog breeds are a model in my web application, with lots of metadata and associations of their own.

All Rails tagging gems I've been able to find simply regard tags as words; I want to know if there is a gem out there that supports tags being objects/models themselves.

I certainly know I can roll my own through just writing some has_many association logic, but what's nice about a lot of the Rails taggable gems is that they come with loads of methods that help querying and displaying the tag data very easy.

1

1 Answers

0
votes

I don't know of any that do exactly what you are asking, but the acts_as_taggable_on gem does support tags in different contexts. Maybe you could create a tag context for dog breed, allow the choice of breed based on your model and then use the name or id for the breed model record as your tag within the breed context. You can find more information here but you would add something like this to your model:

acts_as_taggable #for your normal tags
acts_as_taggable_on :breeds

Then you could find items tagged with a breed using:

Question.tagged_with('border collie', :on => :breeds)

I know this isn't exactly what you were looking for, but this allows you to use the find methods of an existing gem while still allowing you to segment out your tags the way you described.