Search code examples
ruby-on-railsrubyacts-as-taggable-on

Dynamic Tag Context Compliment


This is some of the information provided by the docs for dynamic tag contexts in acts_as_taggable_on...

@user = User.new(:name => "Bobby")
@user.set_tag_list_on(:customs, "same, as, tag, list")
@user.tag_list_on(:customs) # => ["same","as","tag","list"]
@user.save
@user.tags_on(:customs) # => [<Tag name='same'>,...]
@user.tag_counts_on(:customs)
User.tagged_with("same", :on => :customs) # => [@user]

My question is how do I get a compliment of the custom tag list that I create. I want :tags - :customs, that is the set of all tags minus the specified tags of customs.


Solution

  • From their Github page:

    # Find a user that's not tagged with awesome or cool:
    User.tagged_with(["awesome", "cool"], :exclude => true)
    



    Update


    You could try:

    customs_tags = @user.tag_list_on(:customs)
    user_tags = @user.tag_list
    new_tags = user_tags - customs_tags
    
    @user.set_tag_list_on(:customs, new_tags)