Also, you can't define default scope with lambda until Rails 3.1 You can use "unscoped" if you want to override default scope
-- Chirag http://sumeruonrails.com On Thu, Jun 23, 2011 at 11:35 AM, Colin Law <[email protected]> wrote: > On 23 June 2011 00:33, Andrew Skegg <[email protected]> wrote: > > Chirag Singhal <chirag.singhal@...> writes: > > > >> > >> > >> It may sound silly simple, but why not just defined a named scope for > that > > and be done with it. > >> Assuming you are on Rails 3 something like this should work: > >> > >> scope :active, lambda {where(["created_at > ?", 10.days.ago])} > >> > >> > >> > > > > > > Bingo! > > > > Although given what he seems to be attempting here I would make it the > default > > scope: > > > > scope :default, lambda {where(["created_at > ?", 10.days.ago])} > > > > If you want to search for expired messages, just add another scope: > > > > scope :expired, lambda {where(["created_at < ?", 10.days.ago])} > > I am not sure about that, but have not got time to test it now. If > you have a default scope and then add another will not the :expired > scope be applied *as well as* the default, resulting in no records > found at all. > > Also, even if the above does work I think one of the scopes should > include the exact equality, otherwise records that are exactly > 10.days.ago will not be found by either (not that there will be many > as it must be exact to the second I think). > > Colin > > -- > 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. > > -- 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.

