Permalink
Browse files

extract controller and action parsing to a method

  • Loading branch information...
1 parent bc916a7 commit 8d309832df4a32f3bebbbc7ceae800876cef1174 @tenderlove tenderlove committed May 28, 2014
Showing with 26 additions and 19 deletions.
  1. +26 −19 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -240,25 +240,12 @@ def default_controller_and_action
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 @@ def default_controller_and_action
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."

0 comments on commit 8d30983

Please sign in to comment.