Guest User

Untitled

a guest
Feb 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. named_scope :unverified, :conditions => {:verified => false}
  2.  
  3. # This makes a named_scope as desired, but duplicates the code in unverified.
  4. named_scope :inactive, lambda {{ :conditions => ["verified = ? and last_login < ?", false, Time.now - 3.months] } }
  5.  
  6. # We can avoid the duplication with an explicit method. Can't we do this in a named_scope directly?
  7. def self.inactive2
  8. self.unverified.find(:all, :conditions => ["last_login < ?", Time.now - 3. months])
  9. end
  10.  
  11. # e.g.... (but this does not work, natch)
  12. named_scope :inactiv3, lambda { User.inactive + { :conditions => ["last_login < ?", Time.now - 3. months] } }
Add Comment
Please, Sign In to add comment