aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-28 16:49:47 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-28 16:49:47 -0700
commit78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533 (patch)
tree06689df09805bdb3683c46ec5484f3c6fbfcdc1a /actionpack/lib/action_dispatch
parent309ff10d7d895ccb822b426dac3fb0a41e1da193 (diff)
downloadrails-78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533.tar.gz
rails-78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533.tar.bz2
rails-78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533.zip
translate action / controller to the desired object
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb23
1 files changed, 11 insertions, 12 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 5ea694f0ff..d7e0d932fb 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -247,11 +247,8 @@ module ActionDispatch
@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."
@@ -259,11 +256,8 @@ module ActionDispatch
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 @@ module ActionDispatch
[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"