Skip to content

Instantly share code, notes, and snippets.

@karmi
Created December 18, 2008 16:22
Show Gist options
  • Select an option

  • Save karmi/37546 to your computer and use it in GitHub Desktop.

Select an option

Save karmi/37546 to your computer and use it in GitHub Desktop.
# Find all records tagged with a +'tag'+ or ['tag one', 'tag two']
# Pass either String for single tag or Array for multiple tags
def find_all_tagged_with(tag_or_tags)
case tag_or_tags
when Array
all(:include => ['tags', 'taggings']).select { |record| tag_or_tags.all? { |tag| record.tags.map(&:name).include?(tag) } }
when String
all(:include => ['tags', 'taggings']).select { |record| record.tags.map(&:name).include?(tag_or_tags) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment