Created
October 1, 2009 14:57
-
-
Save dpirotte/199027 to your computer and use it in GitHub Desktop.
How to use acts_as_taggable_on with searchlogic!
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
class Post < ActiveRecord::Base | |
acts_as_taggable_on :categories | |
# To deal with a single tag type... | |
scope_procedure :taggable_with_categories, lambda { |tags| | |
tagged_with(tags, :on => :categories) | |
} | |
# Or, deal with all your tag types... | |
if respond_to?(:tag_types) | |
tag_types.each do |tag_type| | |
class_eval <<-EVAL | |
scope_procedure :tagged_with_#{tag_type}, lambda { |tags| | |
tagged_with(tags, :on => :#{tag_type}) | |
} | |
EVAL | |
end | |
end | |
end |
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
# Use tagged_with_* just like you'd use other searchlogic scopes | |
Post.search(:tagged_with_categories => 'fun, awesome') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment