diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-25 15:50:38 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-25 15:50:50 -0700 |
commit | 702965c1b724852afb08e93df64dd65dbcf762d4 (patch) | |
tree | a34292d944657e68537bddac9b80a98507268f3c /actionpack | |
parent | fa54f58733d0e3dbf8572684f6fe0b00ae38c39b (diff) | |
download | rails-702965c1b724852afb08e93df64dd65dbcf762d4.tar.gz rails-702965c1b724852afb08e93df64dd65dbcf762d4.tar.bz2 rails-702965c1b724852afb08e93df64dd65dbcf762d4.zip |
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
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/http/request.rb | 19 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 4 |
2 files changed, 14 insertions, 9 deletions
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 |