From 8d309832df4a32f3bebbbc7ceae800876cef1174 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 28 May 2014 16:23:17 -0700 Subject: extract controller and action parsing to a method --- actionpack/lib/action_dispatch/routing/mapper.rb | 45 ++++++++++++++---------- 1 file changed, 26 insertions(+), 19 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 80c3b867bc..aaf5563dce 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -240,25 +240,12 @@ module ActionDispatch hash = {} return hash if to.respond_to? :call - controller = default_controller - action = default_action - - case to - when Symbol - action = to.to_s - when /#/ - controller, action = to.split('#') - when String - controller = to - end - - if @scope[:module] && !controller.is_a?(Regexp) - if controller =~ %r{\A/} - controller = controller[1..-1] - else - controller = [@scope[:module], controller].compact.join("/") - end - end + controller, action = get_controller_and_action( + default_controller, + default_action, + to, + @scope[:module] + ) if controller.is_a? Regexp hash[:controller] = controller @@ -277,6 +264,26 @@ module ActionDispatch hash end + def get_controller_and_action(controller, action, to, modyoule) + case to + when Symbol + action = to.to_s + when /#/ + controller, action = to.split('#') + when String + controller = to + end + + if modyoule && !controller.is_a?(Regexp) + if controller =~ %r{\A/} + controller = controller[1..-1] + else + controller = [modyoule, controller].compact.join("/") + end + end + [controller, action] + end + def check_action!(action) unless action || segment_keys.include?(:action) message = "Missing :action key on routes definition, please check your routes." -- cgit v1.2.3