将列值相乘并显示它们

时间:2013-11-07 00:25:28

标签: html sql ruby-on-rails

我正在尝试运行订单表的查询以根据用户给定的ID查找订单号,然后根据数量*价格给出订单总数。我有以下

 @ordertotals = Orderlines.where(id: @orderinfo.id).sum("quantity * price")

将把总数放入每个对象的新对象中。然后我试图显示我发现的所有值

<table border=1>
  <tr>
    <td>Order Number</td>
    <td>Order Date</td>
    <td>Cost of Order</td>
  </tr>
    <% # for each customer who has this sales rep
  # display each customer in a row
  for @custdata in @orderinfo   %>
              <tr>
                    <td><%=@orderinfo.id%></td>
                    <td><%=@orderinfo.order_date%></td>
            <% for @orderinfo in @ordertotals %>
                    <td><%=@ordertotals%></td>
            </tr>
            <% end %>
    <% end %>
</table>

首先循环遍历@orderinfo以显示id和订单日期,然后循环遍历@ordertotals以显示每个总数。但是当我运行它时,我在

上遇到了编译器错误
@ordertotals = Orderlines.where(id: @orderinfo.id).sum("quantity * price")

一行,有谁能告诉我这里我做错了什么,以及我打印设置的方式是否有效?

编辑:抱歉忘了在这里添加错误

compile error
/rails1/app/views/ordersdisplay.html.erb:22: syntax error, unexpected ':', expecting ')'
...rtotals = Orderlines.where(id: @orderinfo.id).sum("quantity ...
                          ^
/rails1/app/views/ordersdisplay.html.erb:22: syntax error, unexpected ')', expecting   kEND
...lines.where(id: @orderinfo.id).sum("quantity * price")
                          ^
/rails1/app/views/ordersdisplay.html.erb:55: syntax error, unexpected kENSURE, expecting $end

0 个答案:

没有答案