1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

always return a controller class from the controller_class method

now the caller can just treat it like a regular controller even though
it will return a 404
This commit is contained in:
Aaron Patterson 2015-08-25 15:50:38 -07:00
parent fa54f58733
commit 702965c1b7
2 changed files with 14 additions and 9 deletions

View file

@ -68,16 +68,23 @@ module ActionDispatch
end
end
PASS_NOT_FOUND = Class.new { # :nodoc:
def self.action(_); self; end
def self.call(_); [404, {'X-Cascade' => 'pass'}, []]; end
}
def controller_class
check_path_parameters!
params = path_parameters
controller_param = params[:controller].underscore if params.key?(:controller)
params[:action] ||= 'index'
yield unless controller_param
const_name = "#{controller_param.camelize}Controller"
ActiveSupport::Dependencies.constantize(const_name)
if params.key?(:controller)
controller_param = params[:controller].underscore
params[:action] ||= 'index'
const_name = "#{controller_param.camelize}Controller"
ActiveSupport::Dependencies.constantize(const_name)
else
PASS_NOT_FOUND
end
end
def key?(key)

View file

@ -28,9 +28,7 @@ module ActionDispatch
def serve(req)
params = req.path_parameters
controller = req.controller_class do
return [404, {'X-Cascade' => 'pass'}, []]
end
controller = req.controller_class
dispatch(controller, params[:action], req)
rescue NameError => e
if @raise_on_name_error