Class: Comable::Admin::StocksController
Instance Method Summary
collapse
#current_ability, #respond_to_export_with
Instance Method Details
#create ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/controllers/comable/admin/stocks_controller.rb', line 23
def create
@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
|
#destroy ⇒ Object
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
|
#edit ⇒ Object
35
36
|
# File 'app/controllers/comable/admin/stocks_controller.rb', line 35
def edit
end
|
#export ⇒ Object
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
|
#import ⇒ Object
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
|
#index ⇒ Object
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
|
#new ⇒ Object
20
21
|
# File 'app/controllers/comable/admin/stocks_controller.rb', line 20
def new
end
|
#show ⇒ Object
16
17
18
|
# File 'app/controllers/comable/admin/stocks_controller.rb', line 16
def show
render :edit
end
|
#update ⇒ Object
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
|