mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
venue_commercial association establihed
This commit is contained in:
parent
1fdd029a86
commit
154f4a400c
3 changed files with 61 additions and 0 deletions
58
app/controllers/venue_commercial_controller.rb
Normal file
58
app/controllers/venue_commercial_controller.rb
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
module Admin
|
||||
class CommercialsController < Admin::BaseController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
load_and_authorize_resource :venue ,through: :conference, singelton: true
|
||||
before_action :set_venue
|
||||
|
||||
def create
|
||||
@commercial = @venue.commercial.build(commercial_params)
|
||||
authorize! :create, @commercial
|
||||
|
||||
#FIXME redirect to tab#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
|
||||
|
||||
def set_venue
|
||||
@venue = @conference.venue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
class Venue < ActiveRecord::Base
|
||||
belongs_to :conference
|
||||
has_one :commercial, as: :commercialable, dependent: :destroy
|
||||
has_many :rooms, dependent: :destroy
|
||||
before_create :generate_guid
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ Osem::Application.routes.draw do
|
|||
# Singletons
|
||||
resource :splashpage
|
||||
resource :venue do
|
||||
get 'venue_commercial/render_commercial' => 'venue_commercial#render_commercial'
|
||||
resource :venue_commercial, only: [:create, :update, :destroy]
|
||||
resources :rooms, except: [:show]
|
||||
end
|
||||
resource :registration_period
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue