Sha256: 1678d5450b43af2c591423dd0e4935f06755c91fc6b23a595c33a71810761f39

Contents?: true

Size: 1.57 KB

Versions: 20

Compression:

Stored size: 1.57 KB

Contents

class DiscountsController < ApplicationController
  before_filter :authorize_event, :grab_ticket_type_names

  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

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

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

  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

  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

  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

private

  def authorize_event
    @event = Event.find params[:event_id]
    authorize! :edit, @event
  end

  def grab_ticket_type_names
    @ticket_type_names = @event.charts.includes(:sections => :ticket_types).collect{|c| c.ticket_types.collect{|s| s.name}}.flatten.uniq.sort
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.21 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.20 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.19 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.18 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.17 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.16 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.15 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.12 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.11 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.10 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.9 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.8 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.7 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.6 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.5 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.4 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.3 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.2 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre.1 app/controllers/discounts_controller.rb
artfully_ose-1.2.0.pre app/controllers/discounts_controller.rb