Skip to content

Commit

Permalink
Cart can be viewed from product index
Browse files Browse the repository at this point in the history
  • Loading branch information
Derrick Fonseca committed Nov 19, 2024
1 parent f9da274 commit 0564e18
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/views/items/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<h1>Items</h1>

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

<table>
<thead>
<tr>
Expand Down

0 comments on commit 0564e18

Please sign in to comment.