Class: Comable::Admin::VariantsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability, #respond_to_export_with

Instance Method Details

#createObject



29
30
31
32
33
34
35
36
# File 'app/controllers/comable/admin/variants_controller.rb', line 29

def create
  if @variant.save
    redirect_to comable.admin_product_variant_path(@product, @variant), notice: Comable.t('successful')
  else
    flash.now[:alert] = Comable.t('failure')
    render :new
  end
end

#destroyObject



50
51
52
53
# File 'app/controllers/comable/admin/variants_controller.rb', line 50

def destroy
  @variant.destroy
  redirect_to comable.admin_product_path(@product), notice: Comable.t('successful')
end

#editObject



38
39
# File 'app/controllers/comable/admin/variants_controller.rb', line 38

def edit
end

#indexObject



13
14
15
16
17
18
19
20
# File 'app/controllers/comable/admin/variants_controller.rb', line 13

def index
  @q = @variants.ransack(params[:q])
  @variants = @q.result.includes(:product).page(params[:page]).accessible_by(current_ability).by_newest

  respond_to do |format|
    format.json { render json: @variants }
  end
end

#newObject



26
27
# File 'app/controllers/comable/admin/variants_controller.rb', line 26

def new
end

#showObject



22
23
24
# File 'app/controllers/comable/admin/variants_controller.rb', line 22

def show
  render :edit
end

#updateObject



41
42
43
44
45
46
47
48
# File 'app/controllers/comable/admin/variants_controller.rb', line 41

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