2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2016-04-03 19:25:41 +05:30
|
|
|
module Admin
|
2016-04-03 22:08:46 +05:30
|
|
|
class VenueCommercialsController < Admin::BaseController
|
2016-04-03 19:25:41 +05:30
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
2016-04-09 02:00:32 +05:30
|
|
|
load_and_authorize_resource :venue, through: :conference, singleton: true
|
|
|
|
|
load_and_authorize_resource :commercial, through: :venue, singleton: true
|
2016-04-03 19:25:41 +05:30
|
|
|
|
|
|
|
|
def create
|
2016-04-03 22:08:46 +05:30
|
|
|
@commercial = @venue.build_commercial(commercial_params)
|
2016-04-03 19:25:41 +05:30
|
|
|
authorize! :create, @commercial
|
|
|
|
|
|
|
|
|
|
if @commercial.save
|
2016-04-09 02:52:06 +05:30
|
|
|
redirect_to admin_conference_venue_path,
|
2016-04-03 19:25:41 +05:30
|
|
|
notice: 'Commercial was successfully created.'
|
|
|
|
|
else
|
2016-04-09 02:52:06 +05:30
|
|
|
redirect_to admin_conference_venue_path,
|
2016-04-03 19:25:41 +05:30
|
|
|
error: 'An error prohibited this Commercial from being saved: '\
|
|
|
|
|
"#{@commercial.errors.full_messages.join('. ')}."
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
if @commercial.update(commercial_params)
|
2016-04-09 02:52:06 +05:30
|
|
|
redirect_to admin_conference_venue_path,
|
2016-04-03 19:25:41 +05:30
|
|
|
notice: 'Commercial was successfully updated.'
|
|
|
|
|
else
|
2016-04-09 02:52:06 +05:30
|
|
|
redirect_to admin_conference_venue_path,
|
2016-04-03 19:25:41 +05:30
|
|
|
error: 'An error prohibited this Commercial from being saved: '\
|
|
|
|
|
"#{@commercial.errors.full_messages.join('. ')}."
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
@commercial.destroy
|
2016-04-09 02:52:06 +05:30
|
|
|
redirect_to admin_conference_venue_path, notice: 'Commercial was successfully destroyed.'
|
2016-04-03 19:25:41 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def render_commercial
|
|
|
|
|
result = Commercial.render_from_url(params[:url])
|
|
|
|
|
if result[:error]
|
2019-05-13 17:15:31 +02:00
|
|
|
render plain: result[:error], status: 400
|
2016-04-03 19:25:41 +05:30
|
|
|
else
|
2019-05-13 17:15:31 +02:00
|
|
|
render plain: result[:html]
|
2016-04-03 19:25:41 +05:30
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def commercial_params
|
|
|
|
|
params.require(:commercial).permit(:url)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|