Permalink
Browse files

only error handling between controller and action is the same

  • Loading branch information...
1 parent 6cabf1d commit 3d0dc81a078a738338a49124b7c6636a16319f83 @tenderlove tenderlove committed May 29, 2014
Showing with 16 additions and 18 deletions.
  1. +16 −18 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -246,22 +246,27 @@ def default_controller_and_action
@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 @@ def get_controller_and_action(controller, action, to, modyoule)
[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

0 comments on commit 3d0dc81

Please sign in to comment.