From 78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 28 May 2014 16:49:47 -0700 Subject: translate action / controller to the desired object --- actionpack/lib/action_dispatch/routing/mapper.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'actionpack/lib/action_dispatch') 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" -- cgit v1.2.3