Class: CartItemsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
# File 'app/controllers/cart_items_controller.rb', line 5

def create
  persist_cart if @cart.new_record?
  @cart.add_item(find_cartable)
end

#destroyObject



19
20
21
22
23
24
25
26
# File 'app/controllers/cart_items_controller.rb', line 19

def destroy
  if @cart_item.destroy
    flash[:notice] = t(:cart_item_removed)
    redirect_to cart_path(@cart)
  else
    flash[:notice] = t(:cart_update_failed)
  end
end

#updateObject



10
11
12
13
14
15
16
17
# File 'app/controllers/cart_items_controller.rb', line 10

def update
  if @cart_item.update_attributes(cart_item_params)
    flash[:notice] = t(:cart_updated)
    redirect_to cart_path(cart)
  else
    flash[:notice] = t(:cart_update_failed)
  end
end