aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/mapper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2009-12-27 14:13:03 -0800
committerDavid Heinemeier Hansson <david@loudthinking.com>2009-12-27 14:13:03 -0800
commit95762cbbb3528bcb6a1a8119795df9647daaaab6 (patch)
treea02340f8d1eb0204b0f81afb27f421f54c45abfa /actionpack/lib/action_dispatch/routing/mapper.rb
parent5565bab994af1e54f34df5891c635590d22feea0 (diff)
downloadrails-95762cbbb3528bcb6a1a8119795df9647daaaab6.tar.gz
rails-95762cbbb3528bcb6a1a8119795df9647daaaab6.tar.bz2
rails-95762cbbb3528bcb6a1a8119795df9647daaaab6.zip
Added shorthand for match 'products/overview' that expands to match 'products/overview', :to => 'products#overview', :as => 'products_overview'
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index e655d6a708..3d604158f4 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -43,15 +43,29 @@ module ActionDispatch
def extract_path_and_options(args)
options = args.extract_options!
- if args.empty?
+ case
+ when using_to_shorthand?(args, options)
path, to = options.find { |name, value| name.is_a?(String) }
options.merge!(:to => to).delete(path) if path
+ when using_match_shorthand?(args, options)
+ path = args.first
+ options = { :to => path.gsub("/", "#"), :as => path.gsub("/", "_") }
else
path = args.first
end
[ normalize_path(path), options ]
end
+
+ # match "account" => "account#index"
+ def using_to_shorthand?(args, options)
+ args.empty? && options.present?
+ end
+
+ # match "account/overview"
+ def using_match_shorthand?(args, options)
+ args.present? && options.except(:via).empty? && args.first.exclude?(":")
+ end
def normalize_path(path)
path = nil if path == ""