Permalink
Browse files

translate action / controller to the desired object

  • Loading branch information...
1 parent 309ff10 commit 78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533 @tenderlove tenderlove committed May 28, 2014
Showing with 11 additions and 12 deletions.
  1. +11 −12 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -247,23 +247,17 @@ def default_controller_and_action
@scope[:module]
)
- case controller
- when Regexp
- hash[:controller] = controller
- when String, Symbol
- hash[:controller] = check_controller!(controller).to_s
+ if controller
+ hash[:controller] = translate_controller controller
else
unless segment_keys.include?(:controller)
message = "Missing :controller key on routes definition, please check your routes."
raise ArgumentError, message
end
end
- case action
- when Regexp
- hash[:action] = action
- when String, Symbol
- hash[:action] = action.to_s
+ if action
+ hash[:action] = translate_action action
else
unless segment_keys.include?(:action)
message = "Missing :action key on routes definition, please check your routes."
@@ -294,8 +288,13 @@ def get_controller_and_action(controller, action, to, modyoule)
[controller, action]
end
- def check_controller!(controller)
- return controller if controller =~ /\A[a-z_0-9][a-z_0-9\/]*\z/
+ def translate_action(action)
+ Regexp === action ? action : action.to_s
+ end
+
+ def translate_controller(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"

0 comments on commit 78deb7f

Please sign in to comment.