2014-08-07 07:42:22 +03:00
|
|
|
module Admin
|
2014-08-13 14:37:05 +03:00
|
|
|
class CommercialsController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
2014-08-13 22:46:41 +03:00
|
|
|
load_and_authorize_resource through: :conference, except: [:new, :create]
|
2014-08-05 18:23:42 +02:00
|
|
|
|
2014-08-07 07:42:22 +03:00
|
|
|
def index
|
|
|
|
|
@commercials = @conference.commercials
|
2014-08-05 18:23:42 +02:00
|
|
|
|
2014-08-07 07:42:22 +03:00
|
|
|
@commercial = @conference.commercials.build
|
2014-08-13 14:37:05 +03:00
|
|
|
authorize! :create, @conference.commercials.new
|
2014-08-07 07:42:22 +03:00
|
|
|
end
|
2014-08-05 18:23:42 +02:00
|
|
|
|
2014-08-07 07:42:22 +03:00
|
|
|
def create
|
|
|
|
|
@commercial = @conference.commercials.build(commercial_params)
|
2014-08-13 22:46:41 +03:00
|
|
|
authorize! :create, @commercial
|
2014-08-05 18:23:42 +02:00
|
|
|
|
2014-08-07 07:42:22 +03:00
|
|
|
if @commercial.save
|
|
|
|
|
redirect_to admin_conference_commercials_path,
|
|
|
|
|
notice: 'Commercial was successfully created.'
|
|
|
|
|
else
|
2016-03-10 14:25:38 +05:30
|
|
|
redirect_to admin_conference_commercials_path,
|
|
|
|
|
error: 'An error prohibited this Commercial from being saved: '\
|
|
|
|
|
"#{@commercial.errors.full_messages.join('. ')}."
|
2015-04-22 21:30:32 +02:00
|
|
|
|
2014-08-07 07:42:22 +03:00
|
|
|
end
|
2014-08-05 18:23:42 +02:00
|
|
|
end
|
|
|
|
|
|
2014-08-07 07:42:22 +03:00
|
|
|
def update
|
|
|
|
|
if @commercial.update(commercial_params)
|
|
|
|
|
redirect_to admin_conference_commercials_path,
|
|
|
|
|
notice: 'Commercial was successfully updated.'
|
|
|
|
|
else
|
2016-03-10 14:25:38 +05:30
|
|
|
redirect_to admin_conference_commercials_path,
|
|
|
|
|
error: 'An error prohibited this Commercial from being saved: '\
|
|
|
|
|
"#{@commercial.errors.full_messages.join('. ')}."
|
2014-08-07 07:42:22 +03:00
|
|
|
end
|
2014-08-05 18:23:42 +02:00
|
|
|
end
|
|
|
|
|
|
2014-08-07 07:42:22 +03:00
|
|
|
def destroy
|
|
|
|
|
@commercial.destroy
|
|
|
|
|
redirect_to admin_conference_commercials_path, notice: 'Commercial was successfully destroyed.'
|
|
|
|
|
end
|
2014-08-05 18:23:42 +02:00
|
|
|
|
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-07 07:42:22 +03:00
|
|
|
private
|
2014-08-05 18:23:42 +02:00
|
|
|
|
2014-08-07 07:42:22 +03:00
|
|
|
def commercial_params
|
2015-04-22 21:30:32 +02:00
|
|
|
params.require(:commercial).permit(:url)
|
2014-08-07 07:42:22 +03:00
|
|
|
end
|
2014-08-05 18:23:42 +02:00
|
|
|
end
|
|
|
|
|
end
|