Class: Shoppe::StockLevelAdjustmentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/shoppe/stock_level_adjustments_controller.rb

Constant Summary collapse

SUITABLE_OBJECTS =
['Shoppe::Product']

Instance Method Summary collapse

Instance Method Details

#createObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/shoppe/stock_level_adjustments_controller.rb', line 19

def create
  @new_sla = @item.stock_level_adjustments.build(params[:stock_level_adjustment].permit(:description, :adjustment))
  if @new_sla.save
    if request.xhr?
      @new_sla = @item.stock_level_adjustments.build
      index
    else
      redirect_to stock_level_adjustments_path(:item_id => params[:item_id], :item_type => params[:item_type]), :notice => t('shoppe.stock_level_adjustments.create_notice')
    end
  else
    if request.xhr?
      render :text => @new_sla.errors.full_messages.to_sentence, :status => 422
    else
      index
      flash.now[:alert] = @new_sla.errors.full_messages.to_sentence
      render :action => "index"
    end
  end
end

#indexObject


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

def index
  @stock_level_adjustments = @item.stock_level_adjustments.ordered.page(params[:page]).per(10)
  @new_sla = @item.stock_level_adjustments.build if @new_sla.nil?
  if request.xhr?
    render :action => 'index', :layout => false
  end
end