Class: Comable::Admin::StocksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/comable/admin/stocks_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Instance Method Details

#createObject



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

def create
  if @stock.update_attributes(stock_params)
    redirect_to comable.admin_product_stock_path(@product, @stock), notice: Comable.t('successful')
  else
    flash.now[:alert] = Comable.t('failure')
    render :new
  end
end

#destroyObject



38
39
40
41
42
43
44
45
# File 'app/controllers/comable/admin/stocks_controller.rb', line 38

def destroy
  if @stock.destroy
    redirect_to comable.admin_product_stocks_path(@product), notice: Comable.t('successful')
  else
    flash.now[:alert] = Comable.t('failure')
    render :edit
  end
end

#indexObject



15
16
17
18
# File 'app/controllers/comable/admin/stocks_controller.rb', line 15

def index
  @q = @product.stocks.ransack(params[:q])
  @stocks = @q.result.includes(:product).page(params[:page]).accessible_by(current_ability)
end

#showObject



11
12
13
# File 'app/controllers/comable/admin/stocks_controller.rb', line 11

def show
  render :edit
end

#updateObject



29
30
31
32
33
34
35
36
# File 'app/controllers/comable/admin/stocks_controller.rb', line 29

def update
  if @stock.update_attributes(stock_params)
    redirect_to comable.admin_product_stock_path(@product, @stock), notice: Comable.t('successful')
  else
    flash.now[:alert] = Comable.t('failure')
    render :edit
  end
end