Class: CartController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/templates/cart_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_to_cartObject



3
4
5
6
7
8
# File 'lib/generators/templates/cart_controller.rb', line 3

def add_to_cart
  product = Product.find(params[:id]) 
  @cart = find_cart 
  @cart.add_item(product)
  redirect_to :back
end

#emptyObject



17
18
19
# File 'lib/generators/templates/cart_controller.rb', line 17

def empty
  empty_cart
end

#remove_from_cartObject



10
11
12
13
14
15
# File 'lib/generators/templates/cart_controller.rb', line 10

def remove_from_cart
  product = Product.find(params[:id]) 
  @cart = find_cart 
  @cart.remove_item(product)
  redirect_to :back
end

#showObject



21
22
23
# File 'lib/generators/templates/cart_controller.rb', line 21

def show
  @cart = cart
end