我打印出一个包含行总计的表,但我也希望获得列的总计。下面的代码不起作用,而不是总打印数量,它只是打印出最后一次迭代的值。Rails 3.从数组中获取总计
<% @shipments.each do |shipment| %>
<tr>
<td style="text-align:center;"><%= shipment.file_number %></td>
<td><%= shipment.shipper.company_name %></td>
<td><%= shipment.hbl %></td>
<td><%= shipment.status %></td>
<td><%= shipment.age %></td>
<td><%= shipment.invoice.read_issued_at unless shipment.invoice.nil? %></td>
<td><%= number_to_currency shipment.invoice.customer_total unless shipment.invoice.nil? %></td>
<td><%= number_to_currency shipment.invoice.customer_amount_paid unless shipment.invoice.nil? %></td>
<td><%= number_to_currency shipment.invoice.customer_open_balance unless shipment.invoice.nil? %></td>
</tr>
<%
grand_customer_total = 0
grand_customer_amount_paid = 0
grand_customer_open_balance = 0
grand_customer_total += shipment.invoice.customer_total
grand_customer_amount_paid += shipment.invoice.customer_amount_paid
grand_customer_open_balance += shipment.invoice.customer_open_balance
%>
<% if @shipments.last == shipment %>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<th>Totals</th>
<td><%= number_to_currency grand_customer_total %></td>
<td><%= number_to_currency grand_customer_amount_paid %></td>
<td><%= number_to_currency grand_customer_open_balance %></td>
</tr>
<% end %>