Created
December 18, 2008 16:22
-
-
Save karmi/37546 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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