mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-17 21:54:06 +00:00
Refactoring rooms
This commit is contained in:
parent
2c98ba9711
commit
6a373b5f6c
11 changed files with 135 additions and 52 deletions
|
|
@ -1,26 +1,55 @@
|
|||
module Admin
|
||||
class RoomsController < Admin::BaseController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
authorize_resource through: :conference
|
||||
load_and_authorize_resource through: :conference
|
||||
|
||||
def index
|
||||
authorize! :index, Room.new(conference_id: @conference.id)
|
||||
end
|
||||
|
||||
def show
|
||||
render :rooms_list
|
||||
def edit; end
|
||||
|
||||
def new
|
||||
@room = @conference.rooms.new
|
||||
end
|
||||
|
||||
def create
|
||||
@room = @conference.rooms.new(room_params)
|
||||
if @room.save
|
||||
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title),
|
||||
notice: 'Room successfully created.')
|
||||
else
|
||||
flash[:error] = "Creating Room failed: #{@room.errors.full_messages.join('. ')}."
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @conference.update_attributes(params[:conference])
|
||||
if @room.update_attributes(room_params)
|
||||
redirect_to(admin_conference_rooms_path(
|
||||
conference_id: @conference.short_title),
|
||||
notice: 'Rooms were successfully updated.')
|
||||
notice: 'Room successfully updated.')
|
||||
else
|
||||
redirect_to(admin_conference_rooms_path(
|
||||
conference_id: @conference.short_title),
|
||||
notice: 'Room update failed.')
|
||||
flash[:error] = "Update Room failed: #{@room.errors.full_messages.join('. ')}."
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @room.destroy
|
||||
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title),
|
||||
notice: 'Room successfully deleted.')
|
||||
else
|
||||
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title),
|
||||
error: 'Destroying room failed! ' \
|
||||
"#{@room.errors.full_messages.join('. ')}.")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def room_params
|
||||
params[:room]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue