Skip to content

Instantly share code, notes, and snippets.

@universal
Last active August 29, 2015 14:25
Show Gist options
  • Save universal/2827e2d573f823a02da8 to your computer and use it in GitHub Desktop.
Save universal/2827e2d573f823a02da8 to your computer and use it in GitHub Desktop.
Time.now and rails scopes
#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