Class: DiscountsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/discounts_controller.rb', line 20

def create
  @discount = @event.discounts.build(params[:discount])
  @discount.creator = current_user

  if @discount.save
    flash[:success] = "Discount #{@discount.code} created successfully."
    redirect_to event_discounts_path(@event)
  else
    render :new
  end
end

#destroyObject



43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/discounts_controller.rb', line 43

def destroy
  @discount = Discount.find(params[:id])

  if @discount.destroy
    flash[:success] = "Discount #{@discount.code} was deleted."
  else
    flash[:error] = "Discount #{@discount.code} was not deleted."
  end

  redirect_to event_discounts_path(@event)
end

#editObject



16
17
18
# File 'app/controllers/discounts_controller.rb', line 16

def edit
  @discount = Discount.find(params[:id])
end

#indexObject



4
5
6
7
8
9
10
# File 'app/controllers/discounts_controller.rb', line 4

def index
  @discounts = @event.discounts
  if @discounts.blank?
    flash[:info] = "You don't have any discounts yet. Please create your first one here."
    redirect_to new_event_discount_path(@event)
  end
end

#newObject



12
13
14
# File 'app/controllers/discounts_controller.rb', line 12

def new
  @discount = Discount.new(:event => @event)
end

#updateObject



32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/discounts_controller.rb', line 32

def update
  @discount = Discount.find(params[:id])

  if @discount.update_attributes(params[:discount])
    flash[:success] = "Discount #{@discount.code} updated successfully."
    redirect_to event_discounts_path(@event)
  else
    render :edit
  end
end