Class: Admin::Shop::Discounts::DiscountablesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/admin/shop/discounts/discountables_controller.rb', line 5

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

#destroyObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/admin/shop/discounts/discountables_controller.rb', line 27

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