Ryan Bates' screencast on this topic - http://railscasts.com/episodes/108
- has more details about delaying evaluation of the condition with a
lambda (including optional argument).

How weird, I literally just watched his screencast before reading this
question.


On Oct 8, 8:54 am, Frederick Cheung <[EMAIL PROTECTED]>
wrote:
> On 8 Oct 2008, at 16:36, cjharrelson wrote:
>
>
>
> > Here is a strange one for you:
>
> > I am using rails 2.1.0.  I am also using the Time zones feature.
>
> > I have a User model that has many enrollments.  The Enrollments model
> > has several named scopes, one of which is today:
>
> > # This named scope is adjusted to UTC
> > named_scope :today, :conditions => ["updated_at >= ? AND updated_at
> > <= ?",
> >    Time.zone.now.beginning_of_day.utc, Time.zone.now.end_of_day.utc]
>
> The Time.zone.now is evaluated precisely once: when the model is  
> loaded. Use a lambda (see the section on procedural scopes in the api  
> docs) to do something like
>
> named_scope :today, lambda { :conditions => stuff here is evaluated  
> each time the scope is accessed }
>
> Fred

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
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