aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-12-11 12:46:50 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-11 12:46:50 -0600
commit2297eaed5b195ea42b99d062ad45f87dde9d3c60 (patch)
tree67b90f1e13a88d60170469e281f081711a976194 /actionpack
parent61e9f2023baead046c7f8ba7c89a7496bf49d1be (diff)
downloadrails-2297eaed5b195ea42b99d062ad45f87dde9d3c60.tar.gz
rails-2297eaed5b195ea42b99d062ad45f87dde9d3c60.tar.bz2
rails-2297eaed5b195ea42b99d062ad45f87dde9d3c60.zip
"new" and "edit" name routes always need to be prepend to the
named_route [#3561 state:resolved]
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb29
-rw-r--r--actionpack/test/dispatch/routing_test.rb14
2 files changed, 37 insertions, 6 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 2fa0aab5df..d480af876d 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -338,7 +338,9 @@ module ActionDispatch
with_scope_level(:collection) do
get "(.:format)", :to => :index, :as => resource.collection_name
post "(.:format)", :to => :create
- get "/new(.:format)", :to => :new, :as => "new_#{resource.singular}"
+ with_exclusive_name_prefix :new do
+ get "/new(.:format)", :to => :new, :as => resource.singular
+ end
end
with_scope_level(:member) do
@@ -346,7 +348,9 @@ module ActionDispatch
get "(.:format)", :to => :show, :as => resource.member_name
put "(.:format)", :to => :update
delete "(.:format)", :to => :destroy
- get "/edit(.:format)", :to => :edit, :as => "edit_#{resource.singular}"
+ with_exclusive_name_prefix :edit do
+ get "/edit(.:format)", :to => :edit, :as => resource.singular
+ end
end
end
end
@@ -400,11 +404,8 @@ module ActionDispatch
end
if args.first.is_a?(Symbol)
- begin
- old_name_prefix, @scope[:name_prefix] = @scope[:name_prefix], "#{args.first}_#{@scope[:name_prefix]}"
+ with_exclusive_name_prefix(args.first) do
return match("/#{args.first}(.:format)", options.merge(:to => args.first.to_sym))
- ensure
- @scope[:name_prefix] = old_name_prefix
end
end
@@ -430,6 +431,22 @@ module ActionDispatch
end
private
+ def with_exclusive_name_prefix(prefix)
+ begin
+ old_name_prefix = @scope[:name_prefix]
+
+ if !old_name_prefix.blank?
+ @scope[:name_prefix] = "#{prefix}_#{@scope[:name_prefix]}"
+ else
+ @scope[:name_prefix] = prefix.to_s
+ end
+
+ yield
+ ensure
+ @scope[:name_prefix] = old_name_prefix
+ end
+ end
+
def with_scope_level(kind, resource = parent_resource)
old, @scope[:scope_level] = @scope[:scope_level], kind
old_resource, @scope[:scope_level_resource] = @scope[:scope_level_resource], resource
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 22ef48b668..425796b460 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -228,9 +228,23 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal 'involvements#index', @response.body
assert_equal '/projects/1/involvements', project_involvements_path(:project_id => '1')
+ get '/projects/1/involvements/new'
+ assert_equal 'involvements#new', @response.body
+ assert_equal '/projects/1/involvements/new', new_project_involvement_path(:project_id => '1')
+
get '/projects/1/involvements/1'
assert_equal 'involvements#show', @response.body
assert_equal '/projects/1/involvements/1', project_involvement_path(:project_id => '1', :id => '1')
+
+ put '/projects/1/involvements/1'
+ assert_equal 'involvements#update', @response.body
+
+ delete '/projects/1/involvements/1'
+ assert_equal 'involvements#destroy', @response.body
+
+ get '/projects/1/involvements/1/edit'
+ assert_equal 'involvements#edit', @response.body
+ assert_equal '/projects/1/involvements/1/edit', edit_project_involvement_path(:project_id => '1', :id => '1')
end
end