From 9651ca751c71cb132c47a32291b9647365b617f5 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 22 Jun 2010 19:29:07 -0300 Subject: Add the :path option to match routes when given as symbols. This is specially useful in http helpers for generating routes in scenarios like: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resources :users, :path => 'usuarios' do get :search, :on => :collection, :path => 'pesquisar' end Signed-off-by: José Valim --- actionpack/lib/action_dispatch/routing/mapper.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f2c8e9e97e..e001d10c0f 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -736,10 +736,10 @@ module ActionDispatch return member { match(*args) } end - path_names = options.delete(:path_names) + path = options.delete(:path) if args.first.is_a?(Symbol) - path = path_for_action(args.first, path_names) + path = path_for_action(args.first, path) options = options_for_action(args.first, options) with_exclusive_scope do @@ -860,7 +860,7 @@ module ActionDispatch end end - def path_for_action(action, path_names) + def path_for_action(action, path) case action when :index, :create "#{@scope[:path]}(.:format)" @@ -881,12 +881,12 @@ module ActionDispatch else case @scope[:scope_level] when :collection, :new - "#{@scope[:path]}/#{action_path(action)}(.:format)" + "#{@scope[:path]}/#{action_path(action, path)}(.:format)" else if parent_resource.shallow? - "#{@scope[:shallow_path]}/#{parent_resource.path}/:id/#{action_path(action)}(.:format)" + "#{@scope[:shallow_path]}/#{parent_resource.path}/:id/#{action_path(action, path)}(.:format)" else - "#{@scope[:path]}/#{action_path(action)}(.:format)" + "#{@scope[:path]}/#{action_path(action, path)}(.:format)" end end end @@ -905,9 +905,8 @@ module ActionDispatch end end - def action_path(name, path_names = nil) - path_names ||= @scope[:path_names] - path_names[name.to_sym] || name.to_s + def action_path(name, path = nil) + path || @scope[:path_names][name.to_sym] || name.to_s end def options_for_action(action, options) -- cgit v1.2.3