aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
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/lib/action_dispatch
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/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb29
1 files changed, 23 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