diff options
author | José Valim <jose.valim@gmail.com> | 2010-06-20 00:12:54 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-20 00:12:54 +0200 |
commit | 72725d7b7fefa1231cf63bddf8faa48a44f71295 (patch) | |
tree | 555d743b8ec704d2cf720d6807eac725d0d64176 /actionpack/lib/action_dispatch | |
parent | 0247995d05b3cd3ff5fe32d5fbd8fdd866646909 (diff) | |
parent | 728b9eccad99d22028577e8b06433e8344b15d01 (diff) | |
download | rails-72725d7b7fefa1231cf63bddf8faa48a44f71295.tar.gz rails-72725d7b7fefa1231cf63bddf8faa48a44f71295.tar.bz2 rails-72725d7b7fefa1231cf63bddf8faa48a44f71295.zip |
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 95e56566a3..0018b6485b 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -647,7 +647,9 @@ module ActionDispatch with_scope_level(:new) do scope(*parent_resource.new_scope) do - yield + scope(action_path(:new)) do + yield + end end end end @@ -723,7 +725,17 @@ module ActionDispatch options = options_for_action(args.first, options) with_exclusive_scope do - return match(path, options) + return super(path, options) + end + elsif resource_method_scope? + path = path_for_custom_action + options[:as] = name_for_action(options[:as]) if options[:as] + args.push(options) + + with_exclusive_scope do + scope(path) do + return super + end end end @@ -737,7 +749,7 @@ module ActionDispatch def root(options={}) if @scope[:scope_level] == :resources - with_scope_level(:collection) do + with_scope_level(:nested) do scope(parent_resource.path, :name_prefix => parent_resource.collection_name) do super(options) end @@ -780,12 +792,18 @@ module ActionDispatch [:resource, :resources].include?(@scope[:scope_level]) end + def resource_method_scope? + [:collection, :member, :new].include?(@scope[:scope_level]) + end + def with_exclusive_scope begin old_name_prefix, old_path = @scope[:name_prefix], @scope[:path] @scope[:name_prefix], @scope[:path] = nil, nil - yield + with_scope_level(:exclusive) do + yield + end ensure @scope[:name_prefix], @scope[:path] = old_name_prefix, old_path end @@ -844,10 +862,8 @@ module ActionDispatch end else case @scope[:scope_level] - when :collection + when :collection, :new "#{@scope[:path]}/#{action_path(action)}(.:format)" - when :new - "#{@scope[:path]}/#{action_path(:new)}/#{action_path(action)}(.:format)" else if parent_resource.shallow? "#{@scope[:module]}/#{parent_resource.path}/:id/#{action_path(action)}(.:format)" @@ -858,6 +874,19 @@ module ActionDispatch end end + def path_for_custom_action + case @scope[:scope_level] + when :collection, :new + @scope[:path] + else + if parent_resource.shallow? + "#{@scope[:module]}/#{parent_resource.path}/:id" + else + @scope[:path] + end + end + end + def action_path(name, path_names = nil) path_names ||= @scope[:path_names] path_names[name.to_sym] || name.to_s |