diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4d04934..58dd170 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,9 +1,5 @@ class ApplicationController < ActionController::Base - def require_current_conference - if not current_conference? - redirect_to '/', alert: 'No conference selected' - end - end + include CurrentConferenceAssigning # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. diff --git a/app/controllers/concerns/current_conference_assigning.rb b/app/controllers/concerns/current_conference_assigning.rb new file mode 100644 index 0000000..c2a6f2a --- /dev/null +++ b/app/controllers/concerns/current_conference_assigning.rb @@ -0,0 +1,26 @@ +module CurrentConferenceAssigning + extend ActiveSupport::Concern + + included do + helper_method :current_conference? + helper_method :current_conference + end + + def current_conference? + current_conference.present? + end + + def current_conference + if not @current_conference and params[:conference_id].present? + @current_conference = Conference.find(params[:conference_id]) + end + + @current_conference + end + + def require_current_conference! + if not current_conference? + raise ActionController::RoutingError.new('Not Found') + end + end +end diff --git a/app/controllers/management/management_controller.rb b/app/controllers/management/management_controller.rb index cefbbaf..d50b412 100644 --- a/app/controllers/management/management_controller.rb +++ b/app/controllers/management/management_controller.rb @@ -6,24 +6,6 @@ module Management private - def current_conference? - current_conference.present? - end - helper_method :current_conference? - - def current_conference - if not @current_conference - if @conference - @current_conference = @conference - elsif params[:conference_id].present? - @current_conference = Conference.find(params[:conference_id]) - end - end - - @current_conference - end - helper_method :current_conference - def authorize_user! head :forbidden unless current_user.admin? end