Skip to content

Instantly share code, notes, and snippets.

@dpirotte
Created October 1, 2009 14:57
Show Gist options
  • Save dpirotte/199027 to your computer and use it in GitHub Desktop.
Save dpirotte/199027 to your computer and use it in GitHub Desktop.
How to use acts_as_taggable_on with searchlogic!
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
# 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