KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a list of invoices... @invoices_1_week = Invoice.order("due_date DESC").where("status != 'paid' AND due_date >= ? AND due_date < ?", Date.today, 1.week.from_now) The invoices model has a total attribute. How can I get a sum of the totals in the @invoice_1_week collection? I know I can do it in the view like this... <% week_1_total = 0 %> <% @invoices_1_week.each do |invoice| %> <% week_1_total = week_1_total + invoice.total %> <% end %> <%= week_1_total %> But I'm wondering if there is a more Railsy way of doing it.
Tags (comma-separated)
Save Edits
Cancel