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
|
# File 'app/controllers/comable/admin/stocks_controller.rb', line 23
def create
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
44
45
46
47
48
49
50
51
|
# File 'app/controllers/comable/admin/stocks_controller.rb', line 44
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
32
33
|
# File 'app/controllers/comable/admin/stocks_controller.rb', line 32
def edit
end
|
#export ⇒ Object
53
54
55
56
57
58
|
# File 'app/controllers/comable/admin/stocks_controller.rb', line 53
def export
q = @stocks.ransack(params[:q])
stocks = q.result.includes(:product).accessible_by(current_ability)
respond_to_export_with stocks
end
|
#import ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'app/controllers/comable/admin/stocks_controller.rb', line 60
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(:product).page(params[:page]).accessible_by(current_ability)
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
35
36
37
38
39
40
41
42
|
# File 'app/controllers/comable/admin/stocks_controller.rb', line 35
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
|