aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-28 17:28:59 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-28 17:28:59 -0700
commit3d0dc81a078a738338a49124b7c6636a16319f83 (patch)
tree04ddb6b9f4f821e94388b37151ebe0afc1cdb5dc /actionpack/lib/action_dispatch
parent6cabf1d19f90af0360d195df145ca5977704a61b (diff)
downloadrails-3d0dc81a078a738338a49124b7c6636a16319f83.tar.gz
rails-3d0dc81a078a738338a49124b7c6636a16319f83.tar.bz2
rails-3d0dc81a078a738338a49124b7c6636a16319f83.zip
only error handling between controller and action is the same
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb34
1 files changed, 16 insertions, 18 deletions
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