Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##acts_as_xapian tip - using with association proxies
- ##Named scope
- class Lesson < ActiveRecord::Base
- named_scope :find_with_xapian, lambda { |*args| {:conditions => ["lessons.id in (?)", ActsAsXapian::Search.new([Lesson], args.to_s).results.collect{|x| x[:model].id}]}}
- end
- ##But if we do this instead, we can now do association proxies
- class Lesson < ActiveRecord::Base
- def self.find_with_xapian(search_term, options={})
- ActsAsXapian::Search.new([self], search_term, options).results.collect{|x| x[:model]}
- end
- end
- current_user.lessons.find_with_xapian "something"
- ##That would automatically scope and return lessons that belong to the current user only. Awesome!
Add Comment
Please, Sign In to add comment