Class: Comable::Admin::ProductsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability, #respond_to_export_with

Instance Method Details

#createObject



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

#destroyObject



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

#editObject



29
30
# File 'app/controllers/comable/admin/products_controller.rb', line 29

def edit
end

#exportObject



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

#importObject



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

#indexObject



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

#newObject



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

def new
end

#showObject



13
14
15
# File 'app/controllers/comable/admin/products_controller.rb', line 13

def show
  render :edit
end

#updateObject



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