osem-fcy/app/controllers/admin/venues_controller.rb

63 lines
1.8 KiB
Ruby
Raw Normal View History

2014-11-12 12:12:57 +01:00
module Admin
class VenuesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :venue, through: :conference, singleton: true
def show; end
def new
@venue = @conference.build_venue
end
2014-11-12 12:12:57 +01:00
def edit; end
def create
@venue = @conference.build_venue(venue_params)
if @venue.save
if params[:venue_photos]
create_additional_photos(@venue, params[:venue_photos])
end
redirect_to admin_conference_venue_path,
notice: 'Venue was successfully created.'
else
render :new
end
end
2014-11-12 12:12:57 +01:00
def update
if @venue.update_attributes(venue_params)
if params[:venue_photos]
create_additional_photos(@venue, params[:venue_photos])
end
redirect_to(admin_conference_venue_path(conference_id: @conference.short_title),
2014-11-12 12:12:57 +01:00
notice: 'Venue was successfully updated.')
else
flash[:error] = "Update venue failed: #{@venue.errors.full_messages.join('. ')}."
render :edit
end
end
def destroy
if @venue.destroy
redirect_to admin_conference_venue_path, notice: 'Venue was successfully deleted.'
else
2014-11-30 15:19:19 +02:00
redirect_to admin_conference_venue_path, alert: 'An error prohibited this Venue from being destroyed: '\
"#{@venue.errors.full_messages.join('. ')}."
end
end
private
def venue_params
2015-10-28 18:05:15 +02:00
params.require(:venue).permit(:name, :street, :postalcode, :city, :country, :longitude, :latitude, :description, :website, :photo, :lodgings_attributes, :conference_id)
end
def create_additional_photos(venue, photos)
photos.each { |photo|
venue.venue_photos.create(photo: photo )
}
end
2014-11-12 12:12:57 +01:00
end
end