Class: Shoppe::PromocodesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/shoppe/promocodes_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

#destroyObject



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

#editObject



29
30
31
# File 'app/controllers/shoppe/promocodes_controller.rb', line 29

def edit
  @promocode = Shoppe::Promocode.find(params[:id])
end

#indexObject



6
7
8
# File 'app/controllers/shoppe/promocodes_controller.rb', line 6

def index
  @promocodes = Shoppe::Promocode.all.order(:title)
end

#newObject



10
11
12
# File 'app/controllers/shoppe/promocodes_controller.rb', line 10

def new
  @promocode = Shoppe::Promocode.new
end

#promocode_paramsObject



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

#updateObject



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