HTML表问题从两个数据库表中获取数据

时间:2013-07-20 01:12:52

标签: ruby-on-rails ruby ruby-on-rails-3

我在从两个不同的数据库表中获取数据以便在HTML表格中正确显示时遇到问题。我确定我只是忽略了一些东西,这很容易,但无论出于什么原因,我都无法显示数量,或者显示<td class="sub-total">

需求(您可以将这些视为订单)和项目通过名为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 个答案:

答案 0 :(得分:1)

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