Ruby on Rails Monday, November 15, 2010

On Mon, Nov 15, 2010 at 11:35 AM, KT <malokt@gmail.com> wrote:

Hi all...

I'm trying to create a named_scope for people who were born this
year.  I have an application helper method defining "current_year".

So far, I have this, but it's not filtering correctly.  I think I need
a BETWEEN, maybe?  I know this is something easy I'm just not
seeing... any help is appreciated!

class Person < ActiveRecord::Base
:named_scope  :born_this_year, :conditions => {:dob => :current_year}
end

Assuming your :dob is a date

Try :conditions => ['dob BETWEEN ? AND ?', Date.today.beginning_of_year, Date.today.end_of_year]

--
Erol M. Fornoles

--
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.

No comments:

Post a Comment