clarion/app/controllers/management/conferences_controller.rb
2015-07-12 11:05:38 +03:00

60 lines
1.3 KiB
Ruby

module Management
class ConferencesController < ManagementController
def new
@conference = Conference.new
@conference.tracks.build(name: 'Track 1')
@conference.halls.build(name: 'Hall 1')
end
def create
@conference = Conference.new(conference_params)
if @conference.save
redirect_to management_conference_path(@conference, current_conference: @conference.slug)
else
render :new
end
end
def update
@conference = find_conference
@conference.update(conference_params)
@conference.save
render :edit
end
def edit
@conference = find_conference
end
def index
@conferences = Conference.all.order(start_date: :desc)
end
def show
@conference = find_conference
end
def destroy
@conference = find_conference
@conference.destroy
redirect_to management_root_path(current_conference: nil)
end
private
def find_conference
Conference.find(params[:id])
end
def conference_params
params.require(:conference).permit(
:title, :email, :start_date, :end_date, :description,
tracks_attributes: [:id, :name, :color, :description, :_destroy],
halls_attributes: [:id, :name, :_destroy]
)
end
end
end