mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-18 06:01:12 +00:00
Merge pull request #946 from Shriyanshagro/venue_commercial
Defined Venue has_one Commercial nice new relationship
This commit is contained in:
commit
1fdc2f8efe
7 changed files with 129 additions and 16 deletions
53
app/controllers/admin/venue_commercials_controller.rb
Normal file
53
app/controllers/admin/venue_commercials_controller.rb
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
module Admin
|
||||
class VenueCommercialsController < Admin::BaseController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
load_and_authorize_resource :venue, through: :conference, singleton: true
|
||||
load_and_authorize_resource :commercial, through: :venue, singleton: true
|
||||
|
||||
def create
|
||||
@commercial = @venue.build_commercial(commercial_params)
|
||||
authorize! :create, @commercial
|
||||
|
||||
if @commercial.save
|
||||
redirect_to admin_conference_venue_path,
|
||||
notice: 'Commercial was successfully created.'
|
||||
else
|
||||
redirect_to admin_conference_venue_path,
|
||||
error: 'An error prohibited this Commercial from being saved: '\
|
||||
"#{@commercial.errors.full_messages.join('. ')}."
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @commercial.update(commercial_params)
|
||||
redirect_to admin_conference_venue_path,
|
||||
notice: 'Commercial was successfully updated.'
|
||||
else
|
||||
redirect_to admin_conference_venue_path,
|
||||
error: 'An error prohibited this Commercial from being saved: '\
|
||||
"#{@commercial.errors.full_messages.join('. ')}."
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@commercial.destroy
|
||||
redirect_to admin_conference_venue_path, notice: 'Commercial was successfully destroyed.'
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
def commercial_params
|
||||
params.require(:commercial).permit(:url)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue