Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Teacher
- # This is NOT fine, because it's run at the loading of the class and captures Date.current and stores it in state.
- # If you're caching classes in Rails, this can be static for N number of days that it's kept in cache.
- named_scope :todays, :conditions => ['(due_date >= ?) & (due_date < ?)', Date.current, Date.tomorrow]
- # This is ok, because lambda guarantees that it's run at run time during the call.
- named_scope :todays, lambda{{:conditions => ['(due_date >= ?) & (due_date < ?)', Date.current, Date.tomorrow]}}
- # This is fine because it's not a cached thing and it's an instance method
- def find_todays
- Assigment.find(:all, :conditions => ['(due_date >= ?) & (due_date < ?)', Date.current, Date.tomorrow])
- end
- end
Add Comment
Please, Sign In to add comment