0

Iam having an issue getting data from two different database tables to display properly with in an HTML table. I'm sure I am just overlooking something and this is pretty easy, but for whatever reason I cannot get quantity to display, or the <td class="sub-total"> to display either.

Demands (you can think of these as orders) and items are connected through a table called demand_items. The demand_items table also has the quantity of the item ordered. The page will display but the quantity and the subtotal will not render.

Here is the 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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

When I do that I get every item in the order on the same row so it ends up looking like this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.