2014-08-05 18:23:42 +02:00
class CommercialsController < ApplicationController
2014-08-30 12:08:24 +02:00
load_resource :conference , find_by : :short_title
2014-08-05 18:23:42 +02:00
before_action :set_event
2014-08-30 12:08:24 +02:00
load_and_authorize_resource through : :event
2016-03-01 22:14:11 +05:30
add_flash_types :error , :alert
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
2015-10-25 13:29:02 +02:00
redirect_to edit_conference_program_proposal_path ( conference_id : @conference . short_title , id : @event . id , anchor : 'commercials-content' ) ,
2014-08-05 18:23:42 +02:00
notice : 'Commercial was successfully created.'
else
2016-03-01 22:14:11 +05:30
redirect_to edit_conference_proposal_path ( conference_id : @conference . short_title , id : @event . id , anchor : 'commercials-content' ) , error : " An error prohibited this Commercial from being saved: #{ @commercial . errors . full_messages . join ( '. ' ) } . "
2014-08-05 18:23:42 +02:00
end
end
def update
if @commercial . update ( commercial_params )
2015-10-25 13:29:02 +02:00
redirect_to edit_conference_program_proposal_path ( conference_id : @conference . short_title , id : @event . id , anchor : 'commercials-content' ) ,
2014-08-05 18:23:42 +02:00
notice : 'Commercial was successfully updated.'
else
2016-03-01 22:14:11 +05:30
redirect_to edit_conference_proposal_path ( conference_id : @conference . short_title , id : @event . id , anchor : 'commercials-content' ) , error : " An error prohibited this Commercial from being saved: #{ @commercial . errors . full_messages . join ( '. ' ) } . "
2014-08-05 18:23:42 +02:00
end
end
def destroy
@commercial . destroy
2015-10-25 13:29:02 +02:00
redirect_to edit_conference_program_proposal_path ( conference_id : @conference . short_title , id : @event . id ) ,
2014-08-05 18:23:42 +02:00
notice : 'Commercial was successfully destroyed.'
end
2015-04-22 21:30:32 +02:00
def render_commercial
result = Commercial . render_from_url ( params [ :url ] )
if result [ :error ]
render text : result [ :error ] , status : 400
else
render text : result [ :html ]
end
end
2014-08-05 18:23:42 +02:00
private
def set_event
2015-10-25 13:29:02 +02:00
@event = @conference . program . events . find ( params [ :proposal_id ] )
2014-08-05 18:23:42 +02:00
end
def commercial_params
2015-04-22 21:30:32 +02:00
params . require ( :commercial ) . permit ( :url )
2014-08-05 18:23:42 +02:00
end
end