diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2009-12-27 14:13:03 -0800 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2009-12-27 14:13:03 -0800 |
commit | 95762cbbb3528bcb6a1a8119795df9647daaaab6 (patch) | |
tree | a02340f8d1eb0204b0f81afb27f421f54c45abfa /actionpack/lib/action_dispatch | |
parent | 5565bab994af1e54f34df5891c635590d22feea0 (diff) | |
download | rails-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')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 16 |
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 == "" |