2010-02-03 40 views
0
@people = Person.find(:all, :conditions => ['parent_id = :parent_id', params[:person]]) 

我想要結合基於出生日期的年齡範圍條件以及。Rails - 條件查找

def minimum_age_conditions 
    ["people.birthdate <= ?", Date.today - minimum_age.years] unless minimum_age.blank? 
end 

def maximum_age_conditions 
    ["people.birthdate >= ?", Date.tomorrow - (maximum_age+1).years] unless maximum_age.blank? 
end 

所以,我怎麼能控制的條件聯繫到模型中的這些方法:我的模型,我可以寫類似的身影?或者,將這些全部放在發現的條件部分會更好嗎?

回答