diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index aec5e7a..e067111 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -5,6 +5,8 @@ class ItemsController < ApplicationController # GET /items or /items.json def index @items = Item.all + @cart = Cart.find_or_create_by(id: session[:cart_id]) + session[:cart_id] = @cart.id end # GET /items/1 or /items/1.json diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb index c6ee3ae..92a51aa 100644 --- a/app/views/items/index.html.erb +++ b/app/views/items/index.html.erb @@ -1,5 +1,7 @@

Items

+<%= link_to "View Cart", @cart ? cart_path(@cart) : root_path, class: "button" %> +