diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index a3c6f015d9..e6387768de 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -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) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 4e29476117..065df09f8b 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -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