2014-08-05 18:23:42 +02:00
|
|
|
class CommercialsController < ApplicationController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
2014-08-05 18:23:42 +02:00
|
|
|
before_action :set_event
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource through: @event, except: [:new, :create]
|
2014-08-05 18:23:42 +02:00
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
@commercial = @event.commercials.build
|
2014-08-12 11:51:59 +03:00
|
|
|
authorize! :new, @commercial
|
2014-08-05 18:23:42 +02:00
|
|
|
end
|
|
|
|
|
|
2014-08-12 22:27:02 +03:00
|
|
|
def edit; end
|
2014-08-05 18:23:42 +02:00
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
@commercial = @event.commercials.build(commercial_params)
|
2014-08-12 11:51:59 +03:00
|
|
|
authorize! :create, @commercial
|
2014-08-05 18:23:42 +02:00
|
|
|
|
|
|
|
|
if @commercial.save
|
|
|
|
|
redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id),
|
|
|
|
|
notice: 'Commercial was successfully created.'
|
|
|
|
|
else
|
|
|
|
|
flash[:alert] = "A error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}."
|
|
|
|
|
render :new
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
if @commercial.update(commercial_params)
|
|
|
|
|
redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id),
|
|
|
|
|
notice: 'Commercial was successfully updated.'
|
|
|
|
|
else
|
|
|
|
|
flash[:alert] = "A error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}."
|
|
|
|
|
render :edit
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
@commercial.destroy
|
|
|
|
|
redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id),
|
|
|
|
|
notice: 'Commercial was successfully destroyed.'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def set_event
|
|
|
|
|
@event = @conference.events.find(params[:proposal_id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def commercial_params
|
|
|
|
|
#params.require(:commercial).permit(:commercial_id, :commercial_type)
|
|
|
|
|
params[:commercial]
|
|
|
|
|
end
|
|
|
|
|
end
|