views:

179

answers:

1

In a blog system I'm working on, I want to use tags as a mechanism for deciding where a particular post shows up. I'm using acts_as_taggable_on to set up two contexts, the normal :tags context and then the :audience context.

I'm using an account model to tag the post model like so:

account.tag(post, :with => "cat1, cat2", :on => :audience)

The problem I'm having is retrieving all the tags in a particular context. I'm able to get all the tags like so:

account.owned_tags # => "cat1, cat2, tag1", where tag1 came from the normal tag context

But what I'd like to do is just get the specific tags in a context, like this:

acount.owned_tags_on :audience

Any suggestions? Thanks!

A: 

owned_tags is normal ActiveRecord association:

has_many :owned_tags, :through => :owned_taggings, :source => :tag, :uniq => true

So you can perform find with conditions on it and select tags you need:

account.owned_tags.all(:conditions => ["context = ?", "audience"])
Voyta
Sweet! That's perfect. Thanks!
Gimli