cart summary and refactoring

This commit is contained in:
Karol Selak 2021-03-22 02:49:05 +01:00
parent df7585c5e1
commit c63c6bc448
4 changed files with 20 additions and 8 deletions

View file

@ -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'