我有发票清单...
@invoices_1_week = Invoice.order("due_date DESC").where("status != 'paid' AND due_date >= ? AND due_date < ?", Date.today, 1.week.from_now)
invoices 模型有一个 total 属性。如何获得 @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 的方式来做到这一点。