Class: Spree::Admin::PromotionCodesController
Instance Method Summary
collapse
belongs_to, #destroy, #edit, #update, #update_positions
#set_user_language_locale_key
Instance Method Details
#create ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/spree/admin/promotion_codes_controller.rb', line 34
def create
@promotion = Spree::Promotion.accessible_by(current_ability, :show).find(params[:promotion_id])
@promotion_code = @promotion.promotion_codes.build(value: params[:promotion_code][:value])
if @promotion_code.save
flash[:success] = flash_message_for(@promotion_code, :successfully_created)
redirect_to admin_promotion_promotion_codes_url(@promotion)
else
flash.now[:error] = @promotion_code.errors.full_messages.to_sentence
render_after_create_error
end
end
|
#index ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'app/controllers/spree/admin/promotion_codes_controller.rb', line 8
def index
@promotion = Spree::Promotion.accessible_by(current_ability, :show).find(params[:promotion_id])
@promotion_codes = @promotion.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"
["Content-Type"] = "text/csv"
["Content-disposition"] = "attachment; filename=\"#{filename}\""
end
end
end
|
#new ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/spree/admin/promotion_codes_controller.rb', line 24
def new
@promotion = Spree::Promotion.accessible_by(current_ability, :show).find(params[:promotion_id])
if @promotion.apply_automatically
flash[:error] = t('activerecord.errors.models.spree/promotion_code.attributes.base.disallowed_with_apply_automatically')
redirect_to admin_promotion_promotion_codes_url(@promotion)
else
@promotion_code = @promotion.promotion_codes.build
end
end
|