2013-07-20 178 views
0

Iam從兩個不同的數據庫表中獲取數據以正確顯示在HTML表中時出現問題。我敢肯定,我只是忽略了一些東西,這很容易,但無論什麼原因,我無法獲得數量顯示,或<td class="sub-total">要顯示。HTML表問題從兩個數據庫表中獲取數據

需求(您可以將這些視爲訂單)和項目通過名爲demand_items的表連接。 demand_items表中還包含訂購商品的數量。頁面將顯示,但數量和小計不會呈現。

下面是HTML:

<h3>Order for <%= @demand.customer.name %></h3> 
<h4>Ordered for: <%= @demand.date %></h4> 
<h4>Add Items</h4> 

<%= render 'demands/item_form' %> 

<table class="customer-table"> 
<tr> 
    <th>Item</th> 
    <th>Price</th> 
    <th>Quantity</th> 
    <th>Sub Total</th> 
</tr> 

<% @demand.items.each do |item| %> 
<tr> 
    <td><%= item.name %></td> 
    <td><%= item.price %></td> 
    <% @demand.demand_items do |quantity| %> 
    <td><%= quantity.quantity %></td> 
    <td class="sub-total"><%= (item.price) * (quantity.quantity) %></td> 
    <% end %> 
    <% end %> 

</tr> 

</table> 

回答

1

@demand.demand_items.each do |quantity|..........@demand.demand_items do |quantity|......

+0

而不是當我這樣做,我得到在同一行的順序每一個項目,因此最終看起來[像這樣(HTTP: //imgur.com/FDu6dwX) – Michael