Class: SolidusFriendlyPromotions::Admin::PromotionCodesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/solidus_friendly_promotions/admin/promotion_codes_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#collection_url, #edit_object_url, #new_object_url, #object_url, #parent, #parent_model_name, #routes_proxy

Instance Method Details

#createObject



37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/solidus_friendly_promotions/admin/promotion_codes_controller.rb', line 37

def create
  @promotion_code = @promotion.codes.build(value: params[:promotion_code][:value])

  if @promotion_code.save
    flash[:success] = flash_message_for(@promotion_code, :successfully_created)
    redirect_to solidus_friendly_promotions.admin_promotion_promotion_codes_url(@promotion)
  else
    flash.now[:error] = @promotion_code.errors.full_messages.to_sentence
    render_after_create_error
  end
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/solidus_friendly_promotions/admin/promotion_codes_controller.rb', line 10

def index
  @promotion_codes = @promotion.codes.order(:value)

  respond_to do |format|
    format.html do
      @promotion_codes = @promotion_codes.page(params[:page]).per(50)
    end
    format.csv do
      filename = "promotion-code-list-#{@promotion.id}.csv"
      headers["Content-Type"] = "text/csv"
      headers["Content-disposition"] = "attachment; filename=\"#{filename}\""
    end
  end
end

#newObject



25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/solidus_friendly_promotions/admin/promotion_codes_controller.rb', line 25

def new
  if @promotion.apply_automatically
    flash[:error] = t(
      :disallowed_with_apply_automatically,
      scope: "activerecord.errors.models.solidus_friendly_promotions/promotion_code.attributes.base"
    )
    redirect_to solidus_friendly_promotions.admin_promotion_promotion_codes_url(@promotion)
  else
    @promotion_code = @promotion.codes.build
  end
end