From 95762cbbb3528bcb6a1a8119795df9647daaaab6 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 27 Dec 2009 14:13:03 -0800 Subject: Added shorthand for match 'products/overview' that expands to match 'products/overview', :to => 'products#overview', :as => 'products_overview' --- actionpack/lib/action_dispatch/routing/mapper.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb') 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 == "" -- cgit v1.2.3