Guest User

Untitled

a guest
May 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. ##acts_as_xapian tip - using with association proxies
  2.  
  3. ##Named scope
  4. class Lesson < ActiveRecord::Base
  5. named_scope :find_with_xapian, lambda { |*args| {:conditions => ["lessons.id in (?)", ActsAsXapian::Search.new([Lesson], args.to_s).results.collect{|x| x[:model].id}]}}
  6. end
  7.  
  8. ##But if we do this instead, we can now do association proxies
  9. class Lesson < ActiveRecord::Base
  10. def self.find_with_xapian(search_term, options={})
  11. ActsAsXapian::Search.new([self], search_term, options).results.collect{|x| x[:model]}
  12. end
  13. end
  14.  
  15. current_user.lessons.find_with_xapian "something"
  16.  
  17. ##That would automatically scope and return lessons that belong to the current user only. Awesome!
Add Comment
Please, Sign In to add comment