bfellerath / RESTaurant

RESTaurant app project
0 stars 0 forks source link

Receipt - Displaying items through a join table #6

Closed bfellerath closed 9 years ago

bfellerath commented 9 years ago

As a user I want to have a receipt page so I can look at all the food_items with name and price for one party's item_order.

Right now I have a show.erb page in parties/show.erb. Below is my schema:

ActiveRecord::Schema.define(version: 20150826183516) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "food_items", force: :cascade do |t|
    t.string   "name"
    t.integer  "price"
    t.string   "allergens"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "item_orders", force: :cascade do |t|
    t.integer  "food_item_id"
    t.integer  "party_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "parties", force: :cascade do |t|
    t.integer  "table_number"
    t.boolean  "is_paid",      default: false
    t.datetime "created_at"
    t.datetime "updated_at"
  end

end

And here is my ERD: https://docs.google.com/drawings/d/1cAGfMtF5nY6LI9E4OkUFaa2M-XMv4x8ovtsmkV7_aJc/edit

Right now I am displaying two things on my parties/show.erb:

<h1>All of An individual party's food items</h1>
<h3>receipt</h3>

<a href="/item_orders/new">New item_orders</a><br>
<a href="/item_orders">item orders</a><br>
<a href="/">home</a><br>

<div id="cooldiv" class="row">

<ul>

  <li>

    table number:<%= @party.table_number %>
    <%= @party.is_paid %><br>

  </li>

</ul>

Both

<%= @party.table_number %>

and

<%= @party.is_paid %>

are showing. I want this to be my receipt page so I want to display food_item.name and food_item.price here as well. I have tried different syntax to display this like:

<%=@party.food_item.name%>

and several variations of that syntax.

The error I am getting is: Undefined method 'food_item' if I use the above code or some variation of that. The above line of code is where it says the error is.

I realize that parties does not have a food_item name but I am trying to connect to it through the join table, is this an issue of syntax?

Is it possible that I can't link to those things through the join table and instead I should be in a file like item_orders/show.erb?

Thanks

Bryan

rapala61 commented 9 years ago

in person