2014-08-06 21:14:00 +03:00
|
|
|
module Admin
|
2014-08-13 14:37:05 +03:00
|
|
|
class RoomsController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
2014-11-12 11:37:28 +01:00
|
|
|
load_and_authorize_resource through: :conference
|
2014-08-12 11:51:59 +03:00
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
authorize! :index, Room.new(conference_id: @conference.id)
|
|
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-11-12 11:37:28 +01:00
|
|
|
def edit; end
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
@room = @conference.rooms.new
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
@room = @conference.rooms.new(room_params)
|
|
|
|
|
if @room.save
|
2014-12-18 13:38:40 +01:00
|
|
|
flash[:notice] = 'Room successfully created.'
|
|
|
|
|
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title))
|
2014-11-12 11:37:28 +01:00
|
|
|
else
|
|
|
|
|
flash[:error] = "Creating Room failed: #{@room.errors.full_messages.join('. ')}."
|
|
|
|
|
render :new
|
|
|
|
|
end
|
2014-08-06 21:14:00 +03:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
def update
|
2014-11-12 11:37:28 +01:00
|
|
|
if @room.update_attributes(room_params)
|
2014-12-18 13:38:40 +01:00
|
|
|
flash[:notice] = 'Room successfully updated.'
|
|
|
|
|
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title))
|
2014-08-06 21:14:00 +03:00
|
|
|
else
|
2014-11-12 11:37:28 +01:00
|
|
|
flash[:error] = "Update Room failed: #{@room.errors.full_messages.join('. ')}."
|
|
|
|
|
render :edit
|
2014-08-06 21:14:00 +03:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
2014-11-12 11:37:28 +01:00
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if @room.destroy
|
2014-12-18 13:38:40 +01:00
|
|
|
flash[:notice] = 'Room successfully deleted.'
|
|
|
|
|
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title))
|
2014-11-12 11:37:28 +01:00
|
|
|
else
|
2014-12-18 13:38:40 +01:00
|
|
|
flash[:error] = "Destroying room failed! #{@room.errors.full_messages.join('. ')}."
|
|
|
|
|
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title))
|
2014-11-12 11:37:28 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def room_params
|
|
|
|
|
params[:room]
|
|
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
end
|