clarion/app/controllers/management/conferences_controller.rb

77 lines
1.7 KiB
Ruby
Raw Normal View History

2014-10-14 18:27:28 +03:00
module Management
class ConferencesController < ManagementController
2014-10-14 23:55:17 +03:00
before_action :assign_conference, only: [:edit, :update, :show, :destroy, :open_call_for_papers, :close_call_for_papers]
before_action :assign_conferences, only: [:index, :destroy, :open_call_for_papers, :close_call_for_papers]
2014-10-14 18:27:28 +03:00
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
2015-05-30 17:18:28 +03:00
set_current_conference(@conference)
2015-04-29 13:00:17 +03:00
redirect_to [:management, @conference]
else
render :new
end
2014-10-14 18:27:28 +03:00
end
2014-10-14 23:07:50 +03:00
def update
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
end
2014-10-14 20:34:33 +03:00
def index
2014-10-14 21:58:13 +03:00
end
2014-10-14 23:55:17 +03:00
def show
end
def destroy
@conference.destroy
render 'reload_table'
end
2014-10-14 21:58:13 +03:00
def open_call_for_papers
@conference.call_for_papers_open = true
@conference.save
render 'reload_table'
end
def close_call_for_papers
@conference.call_for_papers_open = false
@conference.save
render 'reload_table'
2014-10-14 20:34:33 +03:00
end
2014-10-14 18:27:28 +03:00
private
def assign_conference
@conference = Conference.find params[:id]
end
2014-10-14 21:58:13 +03:00
def assign_conferences
@conferences = Conference.all.order(start_date: :desc)
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