Skip to content
This repository
Browse code

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
Joe Goggins authored June 18, 2010 tomeric committed June 21, 2010
10  lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb
@@ -30,9 +30,13 @@ def #{tag_type}_from(owner)
30 30
     
31 31
     module InstanceMethods
32 32
       def owner_tags_on(owner, context)
33  
-        base_tags.where([%(#{ActsAsTaggableOn::Tagging.table_name}.context = ? AND
34  
-                           #{ActsAsTaggableOn::Tagging.table_name}.tagger_id = ? AND
35  
-                           #{ActsAsTaggableOn::Tagging.table_name}.tagger_type = ?), context.to_s, owner.id, owner.class.to_s]).all
  33
+        if owner.nil?
  34
+          base_tags.where([%(#{ActsAsTaggableOn::Tagging.table_name}.context = ?), context.to_s]).all                    
  35
+        else
  36
+          base_tags.where([%(#{ActsAsTaggableOn::Tagging.table_name}.context = ? AND
  37
+                             #{ActsAsTaggableOn::Tagging.table_name}.tagger_id = ? AND
  38
+                             #{ActsAsTaggableOn::Tagging.table_name}.tagger_type = ?), context.to_s, owner.id, owner.class.to_s]).all          
  39
+        end
36 40
       end
37 41
 
38 42
       def cached_owned_tag_list_on(context)

0 notes on commit 3d707c2

Please sign in to comment.
Something went wrong with that request. Please try again.