Last active
August 29, 2015 14:25
-
-
Save universal/2827e2d573f823a02da8 to your computer and use it in GitHub Desktop.
Time.now and rails scopes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Rails 3.2.x model code | |
class Model < ActiveRecord::Base | |
#option 1 -- will cache the Time.now value! | |
scope :expired, where('expire_date < ?', Time.now) | |
#option 2 -- re-evaluates every time! | |
scope :expired, -> { where('expire_date < ?', Time.now) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment