clarion/app/controllers/management/conferences_controller.rb

60 lines
1.3 KiB
Ruby
Raw Normal View History

2014-10-14 18:27:28 +03:00
module Management
class ConferencesController < ManagementController
def new
@conference = Conference.new
2014-10-14 23:55:17 +03:00
@conference.tracks.build(name: 'Track 1')
2014-10-14 23:07:50 +03:00
@conference.halls.build(name: 'Hall 1')
2014-10-14 18:27:28 +03:00
end
def create
2015-05-30 17:18:28 +03:00
@conference = Conference.new(conference_params)
2015-04-29 13:00:17 +03:00
if @conference.save
redirect_to management_conference_path(@conference, current_conference: @conference.slug)
2015-04-29 13:00:17 +03:00
else
render :new
end
2014-10-14 18:27:28 +03:00
end
2014-10-14 23:07:50 +03:00
def update
@conference = find_conference
2015-05-30 17:18:28 +03:00
@conference.update(conference_params)
2014-10-14 23:07:50 +03:00
@conference.save
render :edit
end
2014-10-14 18:27:28 +03:00
def edit
@conference = find_conference
2014-10-14 18:27:28 +03:00
end
2014-10-14 20:34:33 +03:00
def index
@conferences = Conference.all.order(start_date: :desc)
2014-10-14 21:58:13 +03:00
end
2014-10-14 23:55:17 +03:00
def show
@conference = find_conference
2014-10-14 23:55:17 +03:00
end
def destroy
@conference = find_conference
2014-10-14 23:55:17 +03:00
@conference.destroy
redirect_to management_root_path(current_conference: nil)
2014-10-14 20:34:33 +03:00
end
2014-10-14 18:27:28 +03:00
private
def find_conference
Conference.find(params[:id])
2014-10-14 21:58:13 +03:00
end
2014-10-14 18:27:28 +03:00
def conference_params
2015-05-30 17:18:28 +03:00
params.require(:conference).permit(
:title, :email, :start_date, :end_date, :description,
tracks_attributes: [:id, :name, :color, :description, :_destroy],
halls_attributes: [:id, :name, :_destroy]
)
2014-10-14 18:27:28 +03:00
end
end
end