diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-28 16:49:47 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-28 16:49:47 -0700 |
commit | 78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533 (patch) | |
tree | 06689df09805bdb3683c46ec5484f3c6fbfcdc1a /actionpack | |
parent | 309ff10d7d895ccb822b426dac3fb0a41e1da193 (diff) | |
download | rails-78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533.tar.gz rails-78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533.tar.bz2 rails-78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533.zip |
translate action / controller to the desired object
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 23 |
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" |