Reputation: 1
Hey guys, im having some problem here due to rails class caching. I have this named_scope
named_scope :current, :conditions => "starts_at <= '#{Time.now.utc.to_formatted_s(:db)}' and finishes_at >= '#{Time.now.utc.to_formatted_s(:db)}'"
The condition Time is not refreshing, all requests are done with the same Time, probably the first used.
Is there a way to work around it?
Upvotes: 0
Views: 106
Reputation: 1916
In order to do that you need to put the scope in a lambda
named_scope :current, lambda { :conditions => ["starts_at <= ? AND finishes_at >= ?", Time.now.utc, Time.now.utc] }
By having it in a lambda the code is executed each time the scope is called, so you always get the current time.
Upvotes: 1