Rails: is the default definition cached by the query cache?

I got a default scope, such as dynamic:

default_scope :conditions => ["departure_date >= ?", DateTime.current.beginning_of_day]

When I use this code, the first day is fine. Let's say the first day is 03/28/2011

But the next day it seems that he is still using "departure_date >= 28-03-2011"

Is caching the default in my cache?

+3
source share
1 answer

The problem is that this code is executed only once when your application loads, and therefore the actual date does not change. You have to change it to load lazily:

default_scope lambda { { :conditions => ["departure_date >= ?", DateTime.current.beginning_of_day] } }

Therefore, it Datetime.current.beginning_of_daywill be evaluated every time you make a request.

+10
source

All Articles