从过去两年中提取捐款后,我试图得出每月捐款的总和(总共 24 个总和),将密钥(每个月)和值(每个月的捐款总和)存储在哈希数组。
这是我到目前为止所得到的:
@donations = Gift.between(Date.today - 2.years, Date.today, :field => gift_date)
@donations.each do |donation|
#logic here that puts gift_amount into the right month (of the 24 months)
# and adds it to the previous balance for that month, ending up with 24 keys
# and sum values.
end
我怎样才能在 Ruby/Rails 中做到这一点?