This is not really a bug, but more due to the way Ruby evaluates when 
things are executed.

    scope :current, where("start <= ? AND expiration > ?", DateTime.now, 
DateTime.now)

The code does use the current date/time, but the catch is that it doesn't 
use the current date/time when the scope is called, but when the model is 
loaded. Meaning, when the console is loaded or the app is started. It never 
updates the date/time used for the scope once it's loaded.

You'll want to use a Proc or lambda in this scenario, so the scope always 
uses the current date/time when the scope is called.

    scope :current, Proc.new { where("start <= ? AND expiration > ?", 
DateTime.now, DateTime.now) }

That way, DateTime.now is only evaluated when the scope is called.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/jonkZutTBNoJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to