aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-14 12:03:08 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-14 12:03:08 -0700
commitb543ee74f4cc44bcef6dac92859c77810e08dbdb (patch)
tree186e725d755f21a9d3a2026d5edfd1ee67bdff03 /actionpack/lib/action_dispatch
parentb10b279b97b0174d6e157d03845921f04f19d0ad (diff)
downloadrails-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`.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb14
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