Refactoring Venue, Lodgings und Rooms

#385
This commit is contained in:
Chrisbr 2014-07-31 12:20:04 +02:00
parent 518e1cc62b
commit 5fe99dd041
26 changed files with 352 additions and 130 deletions

View file

@ -1,23 +1,57 @@
module Admin
class LodgingsController < ApplicationController
before_filter :verify_organizer
before_action :set_lodging, only: [:edit, :update, :destroy]
before_action :set_venue, only: [:index]
def index
@venue = @conference.venue
end
def show
def new
@lodging = @conference.venue.lodgings.build
end
def edit
end
def create
@lodging = @conference.venue.lodgings.build(lodging_params)
if @lodging.save
redirect_to admin_conference_lodgings_path(@conference.short_title), notice: 'Lodging was successfully created.'
else
flash[:alert] = "A error prohibited this Lodging from being saved: #{@lodging.errors.full_messages.join('. ')}."
render :new
end
end
def update
@venue = @conference.venue
if @venue.update_attributes(params[:venue])
if @lodging.update_attributes(lodging_params)
redirect_to(admin_conference_lodgings_path(conference_id: @conference.short_title),
notice: 'Lodgings were successfully updated.')
notice: 'Lodging was successfully updated.')
else
redirect_to(admin_conference_lodgings_path(conference_id: @conference.short_title),
notice: 'Updating lodgings failed!')
flash[:alert] = "A error prohibited this Lodging from being saved: #{@venue.errors.full_messages.join('. ')}."
render :edit
end
end
def destroy
@lodging.destroy
redirect_to admin_conference_lodgings_path, notice: 'Lodging was successfully destroyed.'
end
private
def set_lodging
@lodging = Lodging.find(params[:id])
end
def set_venue
@venue = @conference.venue
end
def lodging_params
params[:lodging]
end
end
end