Class: Shoppe::PromocodesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Shoppe::PromocodesController
- Defined in:
- app/controllers/shoppe/promocodes_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #promocode_params ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'app/controllers/shoppe/promocodes_controller.rb', line 14 def create @promocode = Shoppe::Promocode.new(promocode_params) if @promocode.save redirect_to :promocodes, flash: {notice: 'Promo code has been created successfully'} else render 'new' end end |
#destroy ⇒ Object
23 24 25 26 27 |
# File 'app/controllers/shoppe/promocodes_controller.rb', line 23 def destroy @promocode = Shoppe::Promocode.find params[:id] @promocode.destroy redirect_to @promocode, :notice => "Promo code has been removed successfully" end |
#edit ⇒ Object
29 30 31 |
# File 'app/controllers/shoppe/promocodes_controller.rb', line 29 def edit @promocode = Shoppe::Promocode.find(params[:id]) end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/shoppe/promocodes_controller.rb', line 6 def index @promocodes = Shoppe::Promocode.all.order(:title) end |
#new ⇒ Object
10 11 12 |
# File 'app/controllers/shoppe/promocodes_controller.rb', line 10 def new @promocode = Shoppe::Promocode.new end |
#promocode_params ⇒ Object
42 43 44 |
# File 'app/controllers/shoppe/promocodes_controller.rb', line 42 def promocode_params params[:promocode].permit(:title, :code, :discount_type, :discount_value, :usage_limit, :active_start_date, :active_end_date) end |
#update ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'app/controllers/shoppe/promocodes_controller.rb', line 33 def update @promocode = Shoppe::Promocode.find(params[:id]) if @promocode.update(promocode_params) redirect_to [:edit, @promocode], :flash => {:notice => "Promo code has been updated successfully"} else render :action => "edit" end end |