2014-06-14 21:48:43 +05:30
|
|
|
module Admin
|
2014-08-13 14:37:05 +03:00
|
|
|
class LodgingsController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
2014-11-20 14:57:03 +01:00
|
|
|
load_and_authorize_resource :lodging, through: :conference
|
2014-06-14 21:48:43 +05:30
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-12 12:00:03 +01:00
|
|
|
def new
|
2014-11-20 14:57:03 +01:00
|
|
|
@lodging = @conference.lodgings.new
|
2014-11-12 12:00:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
2014-11-20 14:57:03 +01:00
|
|
|
@lodging = @conference.lodgings.new(lodging_params)
|
2014-11-12 12:00:03 +01:00
|
|
|
if @lodging.save
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_lodgings_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Lodging successfully created.'
|
2014-11-12 12:00:03 +01:00
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Creating Lodging failed: #{@lodging.errors.full_messages.join('. ')}."
|
2014-11-12 12:00:03 +01:00
|
|
|
render :new
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit; end
|
|
|
|
|
|
2014-06-14 21:48:43 +05:30
|
|
|
def update
|
2014-11-12 12:00:03 +01:00
|
|
|
if @lodging.update_attributes(lodging_params)
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_lodgings_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Lodging successfully updated.'
|
2014-11-12 12:00:03 +01:00
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Update Lodging failed: #{@lodging.errors.full_messages.join('. ')}."
|
2014-11-12 12:00:03 +01:00
|
|
|
render :edit
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if @lodging.destroy
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_lodgings_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Lodging successfully deleted.'
|
2014-06-14 21:48:43 +05:30
|
|
|
else
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_lodgings_path(conference_id: @conference.short_title),
|
2014-11-12 12:00:03 +01:00
|
|
|
error: 'Deleting lodging failed.' \
|
2016-03-11 02:08:00 +05:30
|
|
|
"#{@lodging.errors.full_messages.join('. ')}."
|
2014-06-14 21:48:43 +05:30
|
|
|
end
|
|
|
|
|
end
|
2014-11-12 12:00:03 +01:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def lodging_params
|
2016-04-27 15:27:33 +02:00
|
|
|
params.require(:lodging).permit(:name, :description, :picture, :picture_cache, :website_link, :conference_id)
|
2014-11-12 12:00:03 +01:00
|
|
|
end
|
2014-06-14 21:48:43 +05:30
|
|
|
end
|
|
|
|
|
end
|