Class: Admin::LineItemsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/line_items_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/admin/line_items_controller.rb', line 8

def create
  variant = Variant.find(params[:line_item][:variant_id])
  @line_item = @order.add_variant(variant, params[:line_item][:quantity].to_i)

  if @order.save
    respond_with(@line_item) do |format| 
      format.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false }
    end
  else
    #TODO Handle failure gracefully, patches welcome.
  end
end

#destroyObject



21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/admin/line_items_controller.rb', line 21

def destroy
  if @line_item.destroy
    respond_with(@line_item) do |format| 
      format.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false }
    end
  else
    respond_with(@line_item) do |format| 
      format.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false }
    end
  end
end

#load_line_itemObject



56
57
58
# File 'app/controllers/admin/line_items_controller.rb', line 56

def load_line_item
  @line_item = @order.line_items.find params[:id]
end

#load_orderObject



52
53
54
# File 'app/controllers/admin/line_items_controller.rb', line 52

def load_order
  @order = Order.find_by_number! params[:order_id]
end

#newObject



33
34
35
36
37
# File 'app/controllers/admin/line_items_controller.rb', line 33

def new
  respond_with do |format| 
    format.html { render :action => :new, :layout => false }
  end
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/admin/line_items_controller.rb', line 39

def update
  if @line_item.update_attributes(params[:line_item])
    respond_with(@line_item) do |format| 
      format.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false}
    end
  else
    respond_with(@line_item) do |format| 
      format.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false}
    end
  end
end