diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-14 12:03:08 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-14 12:03:08 -0700 |
commit | b543ee74f4cc44bcef6dac92859c77810e08dbdb (patch) | |
tree | 186e725d755f21a9d3a2026d5edfd1ee67bdff03 | |
parent | b10b279b97b0174d6e157d03845921f04f19d0ad (diff) | |
download | rails-b543ee74f4cc44bcef6dac92859c77810e08dbdb.tar.gz rails-b543ee74f4cc44bcef6dac92859c77810e08dbdb.tar.bz2 rails-b543ee74f4cc44bcef6dac92859c77810e08dbdb.zip |
extract method on determining :to from the path
Eventually we'll pull this up and delete `process_path`.
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 2cd13b8696..5cf3d2f3e9 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1564,19 +1564,23 @@ to this: self end - def process_path(options, controller, path, option_path, to, via, formatted, ancho, options_constraintsr) + def get_to_from_path(path, to, action) + return to if to || action + path_without_format = path.sub(/\(\.:format\)$/, '') - if using_match_shorthand?(path_without_format, to, options[:action]) + if using_match_shorthand?(path_without_format) to ||= path_without_format.gsub(%r{^/}, "").sub(%r{/([^/]*)$}, '#\1') to.tr!("-", "_") end + to + end + def process_path(options, controller, path, option_path, to, via, formatted, ancho, options_constraintsr) + to = get_to_from_path(path, to, options[:action]) decomposed_match(path, controller, options, option_path, to, via, formatted, ancho, options_constraintsr) end - def using_match_shorthand?(path, to, action) - return false if to || action - + def using_match_shorthand?(path) path =~ %r{^/?[-\w]+/[-\w/]+$} end |