2 つの異なるデータベース テーブルからデータを取得して 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>