diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-06-03 16:23:39 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-06-03 16:23:39 -0700 |
commit | 3f7e482aed8f67137c6c8382f6c558d7e856b341 (patch) | |
tree | 9068cd5ee19ba8f5a836c6a4e25435333a32adc6 /actionpack | |
parent | f39fad09c1ae2a20f5a3186ab21be3cd8d517fce (diff) | |
download | rails-3f7e482aed8f67137c6c8382f6c558d7e856b341.tar.gz rails-3f7e482aed8f67137c6c8382f6c558d7e856b341.tar.bz2 rails-3f7e482aed8f67137c6c8382f6c558d7e856b341.zip |
push splitting "to" up the callstack
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index a32e4ee0d1..aac5546aa1 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -170,7 +170,13 @@ module ActionDispatch 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 @@ module ActionDispatch 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 @@ module ActionDispatch 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) |