In the Customer model: has_many :shopping_carts In the ShoppingCart model: belongs_to :customer has_many :line_items In the LineItem model: belongs_to :shopping_cart belongs_to :catalog_item In the Catalog model: has_many :line_items
<!-- Original code: <%= f.number_field :customer_id %> --> <% @c = Customer.all %> <% @options_cust = @c.collect do |c| %> <% [c.name, c.id] %> <% end %> <%= f.select :customer_id, @options_cust %>
<!-- <%= f.number_field :catalog_item_id %> --> <% CatalogItem.all.each do |citem| %> <%= f.radio_button :catalog_item_id, citem.id %> <%= citem.title + " " + citem.price.to_s %><br /> <% end %>
Replace @shopping_cart.customer_id by @shopping_cart.customer.nameIn addition, show this information for each line item:
Replace the table in the LineItem index view by this code: <table> <tr> <th>Catalog ID</th> <th>Title</th> <th>Price</th> <th>Quantity</th> <th>Extended Price</th> </tr> <% @shopping_cart.line_items.each do |litem| %> <tr> <td><%= litem.catalog_item.catid %></td> <td><%= litem.catalog_item.title %></td> <td><%= litem.catalog_item.price %></td> <td><%= litem.quantity %></td> <td><%= litem.catalog_item.price * litem.quantity %></td> </tr> <% end %> </table>
<p><%= link_to "Shopping Cart Index", shopping_carts_path %></p> <p><%= link_to "Catalog Item Index", catalog_items_path %></p> <p><%= link_to "Line Item Index", line_items_path %></p>