Sha256: ef4c8ba48acaea54a42e37991a8e42cf586a568d994a8b43f0c68e0f4db21bc3

Contents?: true

Size: 1.65 KB

Versions: 12

Compression:

Stored size: 1.65 KB

Contents

class Admin::Shop::Products::VariantsController < Admin::ResourceController
  
  model_class ShopProductVariant
  
  before_filter :find_product
    
  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
  
  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
  
  private
  
  def find_product
    @shop_product = @shop_product_variant.product || ShopProduct.find(params[:product_id])
  end
  
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
radiant-shop_variants-extension-0.1.2 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop_variants-extension-0.1.1 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop_variants-extension-0.1.0 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop_variants-extension-0.0.4 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop_variants-extension-0.0.3 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop_variants-extension-0.0.1 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop-extension-0.11.6 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop-extension-0.11.5 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop-extension-0.11.4 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop-extension-0.11.3 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop-extension-0.11.1 app/controllers/admin/shop/products/variants_controller.rb
radiant-shop-extension-0.11.0 app/controllers/admin/shop/products/variants_controller.rb