From 3d0dc81a078a738338a49124b7c6636a16319f83 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 28 May 2014 17:28:59 -0700 Subject: only error handling between controller and action is the same --- actionpack/lib/action_dispatch/routing/mapper.rb | 34 +++++++++++------------- 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 58e8ac0201..ab2df76856 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -246,22 +246,27 @@ module ActionDispatch @scope[:module] ) - hash = check_part(:controller, controller, {}) do - translate_controller controller - end - - check_part(:action, action, hash) do - if Regexp === action - action + hash = check_part(:controller, controller, {}) do |part| + if part =~ %r{\A/} + message = "controller name should not start with a slash" else - action.to_s + message = "'#{part}' is not a supported controller name. This can lead to potential routing problems." + message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use" end + + raise ArgumentError, message end + + check_part(:action, action, hash) { |part| + # we never get here in the tests, but I believe this block should + # be the same as the `controller` block. + part.to_s + } end def check_part(name, part, hash) if part - hash[name] = yield + hash[name] = translate_part(name, part) { yield(part) } else unless segment_keys.include?(name) message = "Missing :#{name} key on routes definition, please check your routes." @@ -291,18 +296,11 @@ module ActionDispatch [controller, action] end - def translate_controller(controller) + def translate_part(name, controller) return controller if Regexp === controller return controller.to_s if controller =~ /\A[a-z_0-9][a-z_0-9\/]*\z/ - if controller =~ %r{\A/} - message = "controller name should not start with a slash" - else - message = "'#{controller}' is not a supported controller name. This can lead to potential routing problems." - message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use" - end - - raise ArgumentError, message + yield end def blocks -- cgit v1.2.3