我有一张发票清单……
@invoices_1_week = Invoice.order("due_date DESC").where("status != 'paid' AND due_date >= ? AND due_date < ?",Date.today,1.week.from_now)
发票模型具有总属性.如何在@ invoice_1_week集合中获得总计的总和?
我知道我可以在这样的视图中做到这一点……
<% week_1_total = 0 %> <% @invoices_1_week.each do |invoice| %> <% week_1_total = week_1_total + invoice.total %> <% end %> <%= week_1_total %>
但我想知道是否有更多的Railsy方式.