Class: Spree::Admin::PromotionRulesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/admin/promotion_rules_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/spree/admin/promotion_rules_controller.rb', line 4

def create
  @promotion = Spree::Promotion.find(params[:promotion_id])
  # Remove type key from this hash so that we don't attempt
  # to set it when creating a new record, as this is raises
  # an error in ActiveRecord 3.2.
  promotion_rule_type = params[:promotion_rule].delete(:type)
  @promotion_rule = promotion_rule_type.constantize.new(params[:promotion_rule])
  @promotion_rule.promotion = @promotion
  if @promotion_rule.save
    flash[:success] = I18n.t(:successfully_created, :resource => I18n.t(:promotion_rule))
  end
  respond_to do |format|
    format.html { redirect_to spree.edit_admin_promotion_path(@promotion)}
    format.js   { render :layout => false }
  end
end

#destroyObject



21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/spree/admin/promotion_rules_controller.rb', line 21

def destroy
  @promotion = Spree::Promotion.find(params[:promotion_id])
  @promotion_rule = @promotion.promotion_rules.find(params[:id])
  if @promotion_rule.destroy
    flash[:success] = I18n.t(:successfully_removed, :resource => I18n.t(:promotion_rule))
  end
  respond_to do |format|
    format.html { redirect_to spree.edit_admin_promotion_path(@promotion)}
    format.js   { render :layout => false }
  end
end