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, #respond_to_export_with

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/comable/admin/stocks_controller.rb', line 23

def create
  # TODO: Remove
  @stock.build_variant(product: @product) unless @stock.variant

  if @stock.save
    redirect_to comable.admin_stock_path(@stock), notice: Comable.t('successful')
  else
    flash.now[:alert] = Comable.t('failure')
    render :new
  end
end

#destroyObject



47
48
49
50
51
52
53
54
# File 'app/controllers/comable/admin/stocks_controller.rb', line 47

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

#editObject



35
36
# File 'app/controllers/comable/admin/stocks_controller.rb', line 35

def edit
end

#exportObject



56
57
58
59
60
61
# File 'app/controllers/comable/admin/stocks_controller.rb', line 56

def export
  q = @stocks.ransack(params[:q])
  stocks = q.result.includes(variant: :product).accessible_by(current_ability)

  respond_to_export_with stocks
end

#importObject



63
64
65
66
67
68
69
70
# File 'app/controllers/comable/admin/stocks_controller.rb', line 63

def import
  ActiveRecord::Base.transaction do
    Comable::Stock.import_from(params[:file])
  end
  redirect_to comable.admin_stocks_path, notice: Comable.t('successful')
rescue Comable::Importable::Exception => e
  redirect_to comable.admin_stocks_path, alert: e.message
end

#indexObject



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

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

#newObject



20
21
# File 'app/controllers/comable/admin/stocks_controller.rb', line 20

def new
end

#showObject



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

def show
  render :edit
end

#updateObject



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

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