我有一个联系人对象数组...
[#<Contact id: 371, full_name: "Don Hofton", birthday: "2013-11-07">,...]
而且我需要按最接近当前时间的生日对它们进行排序,并从数组中删除生日超过 4 个月的对象。这是我到目前为止所得到的,但它不起作用....
@contacts_with_birthday_data = Contact.where(:user_id => current_user.id).where("birthday IS NOT NULL")
@current_time = Time.now
@contacts_with_birthday_data.each do |c|
c.birthday = c.birthday[0..4]
c.birthday = Date.parse(c.birthday)
end
@contacts_with_birthday_data = @contacts_with_birthday_data.sort! { |a,b| b[:birthday] <=> a[:birthday] }
@contacts_with_birthday_data = @contacts_with_birthday_data.sort! { |a| a.birthday < DateTime.now }