cart summary and refactoring
This commit is contained in:
parent
df7585c5e1
commit
c63c6bc448
4 changed files with 20 additions and 8 deletions
|
@ -25,6 +25,8 @@ class BooksController < ApplicationController
|
|||
|
||||
def add_to_cart
|
||||
@book = Book.find(params[:id])
|
||||
return unless @book.quantity.positive?
|
||||
|
||||
current_user.books << @book
|
||||
@book.decrement!(:quantity)
|
||||
redirect_to '/books', notice: 'Book added to your cart'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue