Extract current_conference assignment in a concern
This commit is contained in:
parent
8f7185810e
commit
c4db0ff920
|
@ -1,9 +1,5 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
def require_current_conference
|
include CurrentConferenceAssigning
|
||||||
if not current_conference?
|
|
||||||
redirect_to '/', alert: 'No conference selected'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Prevent CSRF attacks by raising an exception.
|
# Prevent CSRF attacks by raising an exception.
|
||||||
# For APIs, you may want to use :null_session instead.
|
# For APIs, you may want to use :null_session instead.
|
||||||
|
|
|
@ -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
|
|
@ -6,24 +6,6 @@ module Management
|
||||||
|
|
||||||
private
|
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!
|
def authorize_user!
|
||||||
head :forbidden unless current_user.admin?
|
head :forbidden unless current_user.admin?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue