Permalink
Browse files

push splitting "to" up the callstack

  • Loading branch information...
1 parent f39fad0 commit 3f7e482aed8f67137c6c8382f6c558d7e856b341 @tenderlove tenderlove committed Jun 3, 2014
Showing with 20 additions and 15 deletions.
  1. +20 −15 actionpack/lib/action_dispatch/routing/mapper.rb
View
35 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -170,7 +170,13 @@ def normalize_options!(options, formatted, path_params, path_ast, modyoule)
if to.respond_to? :call
options
else
- options.merge!(default_controller_and_action(path_params, modyoule))
+ to_endpoint = split_to to
+ controller = to_endpoint[0] || default_controller
+ action = to_endpoint[1] || default_action
+
+ controller = add_controller_module(controller, modyoule)
+
+ options.merge! check_controller_and_action(path_params, controller, action)
end
end
@@ -250,13 +256,7 @@ def app(blocks)
end
end
- def default_controller_and_action(path_params, modyoule)
- controller, action = get_controller_and_action(default_controller,
- default_action,
- to,
- modyoule
- )
-
+ def check_controller_and_action(path_params, controller, action)
hash = check_part(:controller, controller, path_params, {}) do |part|
translate_controller(part) {
message = "'#{part}' is not a supported controller name. This can lead to potential routing problems."
@@ -283,25 +283,30 @@ def check_part(name, part, path_params, hash)
hash
end
- def get_controller_and_action(controller, action, to, modyoule)
+ def split_to(to)
case to
when Symbol
ActiveSupport::Deprecation.warn "defining a route where `to` is a symbol is deprecated. Please change \"to: :#{to}\" to \"action: :#{to}\""
- action = to.to_s
- when /#/ then controller, action = to.split('#')
+ [nil, to.to_s]
+ when /#/ then to.split('#')
when String
ActiveSupport::Deprecation.warn "defining a route where `to` is a controller without an action is deprecated. Please change \"to: :#{to}\" to \"controller: :#{to}\""
- controller = to
+ [to, nil]
+ else
+ []
end
+ end
+ def add_controller_module(controller, modyoule)
if modyoule && !controller.is_a?(Regexp)
if controller =~ %r{\A/}
- controller = controller[1..-1]
+ controller[1..-1]
else
- controller = [modyoule, controller].compact.join("/")
+ [modyoule, controller].compact.join("/")
end
+ else
+ controller
end
- [controller, action]
end
def translate_controller(controller)

0 comments on commit 3f7e482

Please sign in to comment.