Class: Comable::Admin::ProductsController
Instance Method Summary
collapse
#current_ability, #respond_to_export_with
Instance Method Details
#create ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'app/controllers/comable/admin/products_controller.rb', line 20
def create
if @product.save
redirect_to comable.admin_product_path(@product), notice: Comable.t('successful')
else
flash.now[:alert] = Comable.t('failure')
render :new
end
end
|
#destroy ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'app/controllers/comable/admin/products_controller.rb', line 41
def destroy
if @product.destroy
redirect_to comable.admin_products_path, notice: Comable.t('successful')
else
flash.now[:alert] = Comable.t('failure')
render :edit
end
end
|
#edit ⇒ Object
29
30
|
# File 'app/controllers/comable/admin/products_controller.rb', line 29
def edit
end
|
#export ⇒ Object
50
51
52
53
54
55
|
# File 'app/controllers/comable/admin/products_controller.rb', line 50
def export
q = Comable::Product.ransack(params[:q])
products = q.result.accessible_by(current_ability)
respond_to_export_with products
end
|
#import ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'app/controllers/comable/admin/products_controller.rb', line 57
def import
ActiveRecord::Base.transaction do
Comable::Product.import_from(params[:file])
end
redirect_to comable.admin_products_path, notice: Comable.t('successful')
rescue Comable::Importable::Exception => e
redirect_to comable.admin_products_path, alert: e.message
end
|
#index ⇒ Object
8
9
10
11
|
# File 'app/controllers/comable/admin/products_controller.rb', line 8
def index
@q = Comable::Product.ransack(params[:q])
@products = @q.result(distinct: true).includes(:stocks, :images).page(params[:page]).accessible_by(current_ability)
end
|
#new ⇒ Object
17
18
|
# File 'app/controllers/comable/admin/products_controller.rb', line 17
def new
end
|
#show ⇒ Object
13
14
15
|
# File 'app/controllers/comable/admin/products_controller.rb', line 13
def show
render :edit
end
|
#update ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'app/controllers/comable/admin/products_controller.rb', line 32
def update
if @product.update_attributes(product_params)
redirect_to comable.admin_product_path(@product), notice: Comable.t('successful')
else
flash.now[:alert] = Comable.t('failure')
render :edit
end
end
|