Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

This commit allows you get all tags for a custom context owned or uno…

…wned by specifying nil to owner_tags_on.

I searched the codebase for a while but could not find a way to get both with one call,
and didn't want to invoke both methods then merge them in my controller, thus I added this simple functionality

So now you can do this to get all tags for a given custom context

  @thing.owner_tags_on(nil,:custom_context)
  • Loading branch information...
commit 3d707c25d45b5cc680cf3623d15ff59856457ea9 1 parent fae4236
@joegoggins joegoggins authored tomeric committed
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb
View
10 lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb
@@ -30,9 +30,13 @@ def #{tag_type}_from(owner)
module InstanceMethods
def owner_tags_on(owner, context)
- base_tags.where([%(#{ActsAsTaggableOn::Tagging.table_name}.context = ? AND
- #{ActsAsTaggableOn::Tagging.table_name}.tagger_id = ? AND
- #{ActsAsTaggableOn::Tagging.table_name}.tagger_type = ?), context.to_s, owner.id, owner.class.to_s]).all
+ if owner.nil?
+ base_tags.where([%(#{ActsAsTaggableOn::Tagging.table_name}.context = ?), context.to_s]).all
+ else
+ base_tags.where([%(#{ActsAsTaggableOn::Tagging.table_name}.context = ? AND
+ #{ActsAsTaggableOn::Tagging.table_name}.tagger_id = ? AND
+ #{ActsAsTaggableOn::Tagging.table_name}.tagger_type = ?), context.to_s, owner.id, owner.class.to_s]).all
+ end
end
def cached_owned_tag_list_on(context)
Please sign in to comment.
Something went wrong with that request. Please try again.