Class: DmEvent::Admin::WorkshopPricesController

Inherits:
AdminController
  • Object
show all
Includes:
PermittedParams
Defined in:
app/controllers/dm_event/admin/workshop_prices_controller.rb

Instance Method Summary collapse

Methods included from PermittedParams

#registration_params, #system_email_params, #workshop_params, #workshop_price_params

Instance Method Details

#createObject




25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/dm_event/admin/workshop_prices_controller.rb', line 25

def create
  authorize! :manage_events, @workshop
  attributes = WorkshopPrice.prepare_prices(workshop_price_params.merge(price_currency: @workshop.base_currency))
  @workshop_price = @workshop.workshop_prices.new(attributes)
  if @workshop_price.save
    redirect_to admin_workshop_workshop_prices_url(@workshop), notice: 'Price was successfully created.'
  else
    render action: :new
  end
end

#destroyObject




48
49
50
51
52
53
54
55
56
# File 'app/controllers/dm_event/admin/workshop_prices_controller.rb', line 48

def destroy
  authorize! :manage_events, @workshop
  if @workshop_price.registrations.count == 0
    @workshop_price.destroy
    redirect_to admin_workshop_workshop_prices_url(@workshop), notice: 'Price was successfully deleted.'
  else
    redirect_to admin_workshop_workshop_prices_url(@workshop), error: 'Registrations are using this price - unable to delete'
  end
end

#editObject




20
21
22
# File 'app/controllers/dm_event/admin/workshop_prices_controller.rb', line 20

def edit
  authorize! :manage_events, @workshop
end

#indexObject




8
9
10
11
# File 'app/controllers/dm_event/admin/workshop_prices_controller.rb', line 8

def index
  authorize! :manage_events, @workshop
  @workshop_prices  = @workshop.workshop_prices
end

#newObject




14
15
16
17
# File 'app/controllers/dm_event/admin/workshop_prices_controller.rb', line 14

def new
  authorize! :manage_events, @workshop
  @workshop_price = @workshop.workshop_prices.build(price_currency: @workshop.base_currency)
end

#sortObject




59
60
61
62
63
64
# File 'app/controllers/dm_event/admin/workshop_prices_controller.rb', line 59

def sort
  @workshop_price.update_attribute(:row_order_position, params[:item][:row_order_position])

  #--- this action will be called via ajax
  render nothing: true
end

#updateObject




37
38
39
40
41
42
43
44
45
# File 'app/controllers/dm_event/admin/workshop_prices_controller.rb', line 37

def update
  authorize! :manage_events, @workshop
  attributes = WorkshopPrice.prepare_prices(workshop_price_params.merge(price_currency: @workshop.base_currency))
  if @workshop_price.update_attributes(attributes)
    redirect_to admin_workshop_workshop_prices_url(@workshop), notice: 'Price was successfully updated.'
  else
    render action: :edit
  end
end