Monday, November 15, 2010

[Rails] Re: Filter records by dates occurring this year

Thanks all -. I ended up having to use a lambda:

named_scope :born_this_year, lambda { |year| { :conditions => ['dob
between ? and ?', Date.today.beginning_of_year,
Date.today.end_of_year]}}

I love this group. :)


On Nov 15, 6:33 pm, KT <mal...@gmail.com> wrote:
> Thanks for your responses everyone.  Sorry for the delay in re-
> posting, I've been away from computer.
>
> @Erol   :current_year is an application helper method to pull the
> current year!
> I'll try your suggestions, as well and report back.  Thank you
>
> @Hassan  I will try a debugger, too - thanks for the reminder.
>
> On Nov 15, 2:31 am, Erol Fornoles <erol.forno...@gmail.com> wrote:
>
> > On Mon, Nov 15, 2010 at 6:24 PM, Erol Fornoles <erol.forno...@gmail.com>wrote:
>
> > > Assuming your :dob is a date
>
> > > Try :conditions => ['dob BETWEEN ? AND ?', Date.today.beginning_of_year,
> > > Date.today.end_of_year]
>
> > Wait let me correct that, but first, is :current_year a field or column in
> > your table or a parameter that was meant to be passed to the named_scope?
>
> > --
> > Erol M. Fornoleshttp://github.com/Erolhttp://twitter.com/erolfornoleshttp://ph.linked...

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate