我正在尝试对订单表进行查询,以根据用户给定的 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