diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-28 18:03:26 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-28 18:03:26 -0700 |
commit | d311922c82ace9de7ca588b47a54716835bdca2a (patch) | |
tree | 2241aecb70c52abdf0a09093c015a428d4d9a69f /actionpack/lib | |
parent | 75bfe647834bc9e46d6400c21cd8ffeb80cffd89 (diff) | |
download | rails-d311922c82ace9de7ca588b47a54716835bdca2a.tar.gz rails-d311922c82ace9de7ca588b47a54716835bdca2a.tar.bz2 rails-d311922c82ace9de7ca588b47a54716835bdca2a.zip |
only validate controllers
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 132bf4473e..899f0fdc1b 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -127,7 +127,11 @@ module ActionDispatch options[:controller] ||= /.+?/ end - options.merge!(default_controller_and_action) + if to.respond_to? :call + options + else + options.merge!(default_controller_and_action) + end end def normalize_requirements! @@ -237,8 +241,6 @@ module ActionDispatch end def default_controller_and_action - return {} if to.respond_to? :call - controller, action = get_controller_and_action(default_controller, default_action, to, @@ -246,26 +248,26 @@ module ActionDispatch ) hash = check_part(:controller, controller, {}) do |part| - if part =~ %r{\A/} - message = "controller name should not start with a slash" - else - message = "'#{part}' is not a supported controller name. This can lead to potential routing problems." - message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use" - end + translate_controller(part) { + if part =~ %r{\A/} + message = "controller name should not start with a slash" + else + message = "'#{part}' is not a supported controller name. This can lead to potential routing problems." + message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use" + end - raise ArgumentError, message + raise ArgumentError, message + } end check_part(:action, action, hash) { |part| - # we never get here in the tests, but I believe this block should - # be the same as the `controller` block. - part.to_s + part.is_a?(Regexp) ? part : part.to_s } end def check_part(name, part, hash) if part - hash[name] = translate_part(name, part) { yield(part) } + hash[name] = yield(part) else unless segment_keys.include?(name) message = "Missing :#{name} key on routes definition, please check your routes." @@ -292,7 +294,7 @@ module ActionDispatch [controller, action] end - def translate_part(name, controller) + 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/ |