Class: Admin::Shop::Products::VariantsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/admin/shop/products/variants_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/admin/shop/products/variants_controller.rb', line 7

def create
  notice  = 'Successfully created variant.'
  error   = 'Could not create variant.'
  
  begin
    @shop_product_variant.attributes = params[:shop_product_variant]
    @shop_product_variant.save!
    
    respond_to do |format|
      format.html {
        redirect_to edit_admin_shop_product_path(@shop_product)
      }
      format.js   { render :partial => '/admin/shop/products/edit/shared/variant', :locals => { :variant => @shop_product_variant } }
    end
  rescue
    respond_to do |format|
      format.html {
        flash[:error] = error
        redirect_to edit_admin_shop_product_path(@shop_product)
      }
      format.js   { render :text  => error, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/admin/shop/products/variants_controller.rb', line 32

def destroy
  notice  = 'Successfully destroyed variant.'
  error   = 'Could not destroy variant.'
  
  if @shop_product_variant.destroy
    respond_to do |format|
      format.html {
        redirect_to edit_admin_shop_product_path(@shop_product)
      }
      format.js   { render :text  => notice, :status => :ok }
    end
  else
    respond_to do |format|
      format.html {
        flash[:error] = error
        redirect_to edit_admin_shop_product_path(@shop_product)
      }
      format.js   { render :text  => error, :status => :unprocessable_entity }
    end
  end
end