Guest User

Untitled

a guest
Jun 23rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class Teacher
  2.  
  3. # This is NOT fine, because it's run at the loading of the class and captures Date.current and stores it in state.
  4. # If you're caching classes in Rails, this can be static for N number of days that it's kept in cache.
  5. named_scope :todays, :conditions => ['(due_date >= ?) & (due_date < ?)', Date.current, Date.tomorrow]
  6.  
  7. # This is ok, because lambda guarantees that it's run at run time during the call.
  8. named_scope :todays, lambda{{:conditions => ['(due_date >= ?) & (due_date < ?)', Date.current, Date.tomorrow]}}
  9.  
  10. # This is fine because it's not a cached thing and it's an instance method
  11. def find_todays
  12. Assigment.find(:all, :conditions => ['(due_date >= ?) & (due_date < ?)', Date.current, Date.tomorrow])
  13. end
  14. end
Add Comment
Please, Sign In to add comment