Sha256: ab8c0c0616d1978e8a2b5ceb42c94ad78a38cfa346f7cc2d186f789f136306df

Contents?: true

Size: 1.37 KB

Versions: 10

Compression:

Stored size: 1.37 KB

Contents

class Admin::Shop::Discounts::DiscountablesController < Admin::ResourceController
  
  model_class ShopDiscountable
  
  def create
    error = 'Could not attach Discount.'
    begin
      @shop_discountable.attributes = {
        :discount_id     => params[:discount_id],
        :discounted_id   => params[:discounted_id],
        :discounted_type => params[:discounted_type]
      }
      @shop_discountable.save!
      
      discounted_type = @shop_discountable.discounted_type.gsub('Shop','').underscore
      
      respond_to do |format|
        format.js { render :partial => "admin/shop/discounts/edit/shared/#{discounted_type}", :locals => { discounted_type.to_sym => @shop_discountable } }
      end
    rescue
      respond_to do |format|
        format.js { render :text => error, :status => :unprocessable_entity }
      end
    end
  end
  
  def destroy
    error = 'Could not remove Discount.'
    begin
      discounted_type = @shop_discountable.discounted_type.gsub('Shop','').underscore
      
      @shop_discountable.destroy
      
      respond_to do |format|
        format.js { render :partial => "admin/shop/discounts/edit/shared/#{discounted_type}", :locals => { discounted_type.to_sym => @shop_discountable } }
      end
    rescue
      respond_to do |format|
        format.js { render :text => error, :status => :unprocessable_entity }
      end
    end
  end
  
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
radiant-shop_discounts-extension-0.0.11 app/controllers/admin/shop/discounts/discountables_controller.rb
radiant-shop_discounts-extension-0.0.10 app/controllers/admin/shop/discounts/discountables_controller.rb
radiant-shop_discounts-extension-0.0.9 app/controllers/admin/shop/discounts/discountables_controller.rb
radiant-shop_discounts-extension-0.0.8 app/controllers/admin/shop/discounts/discountables_controller.rb
radiant-shop_discounts-extension-0.0.7 app/controllers/admin/shop/discounts/discountables_controller.rb
radiant-shop_discounts-extension-0.0.6 app/controllers/admin/shop/discounts/discountables_controller.rb
radiant-shop_discounts-extension-0.0.4 app/controllers/admin/shop/discounts/discountables_controller.rb
radiant-shop_discounts-extension-0.0.3 app/controllers/admin/shop/discounts/discountables_controller.rb
radiant-shop_discounts-extension-0.0.1 app/controllers/admin/shop/discounts/discountables_controller.rb
radiant-shop-extension-0.11.6 app/controllers/admin/shop/discounts/discountables_controller.rb