Class: CartItemsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

RESTful equiv of add



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

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

#destroyObject



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

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



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

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