Class: TbCheckout::CartItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tb_checkout/cart_items_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/tb_checkout/cart_items_controller.rb', line 6

def create
  @cart_item = @cart.cart_items.create(cart_item_params)
  respond_with @cart_item do |format|
    format.html{
      if @cart_item.errors.any?
        flash[:error] = "An error occurred: \"#{@cart_item.errors.full_messages.first}\""
        redirect_to :back
      else
        flash[:notice] = "Added \"#{@cart_item.item_description}\" to your cart"
        redirect_to tb_checkout_cart_path
      end
    }
  end
end

#destroyObject



36
37
38
39
40
41
42
43
44
# File 'app/controllers/tb_checkout/cart_items_controller.rb', line 36

def destroy
  @cart_item.destroy()
  respond_with @cart_item do |format|
    format.html{
      flash[:notice] = "Removed \"#{@cart_item.item_description}\" from your cart"
      redirect_to tb_checkout_cart_path
    }
  end
end

#updateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/tb_checkout/cart_items_controller.rb', line 21

def update
  @cart_item.update_attributes(cart_item_params)
  respond_with @cart_item do |format|
    format.html{
      if @cart_item.errors.any?
        flash[:error] = "An error occurred: \"#{@cart_item.errors.full_messages.first}\""
        redirect_to :back
      else
        flash[:notice] = "Updated \"#{@cart_item.item_description}\" in your cart"
        redirect_to tb_checkout_cart_path
      end
    }
  end
end