提交 6a8dcc8a 编写于 作者: J Jamis Buck

Make sure map.resources(:things, :new => { :new => :any }) correctly sets...

Make sure map.resources(:things, :new => { :new => :any }) correctly sets /things/new to be accessible by any method rather than creating another resource at /things/new;new


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5195 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 a0bf0195
......@@ -46,6 +46,7 @@ def arrange_actions
def add_default_actions
add_default_action(member_methods, :get, :edit)
add_default_action(new_methods, :get, :new)
end
def set_prefixes
......@@ -253,13 +254,15 @@ def map_new_actions(map, resource)
resource.new_methods.each do |method, actions|
route_options = requirements_for(method)
actions.each do |action|
map.named_route("#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path};#{action}", route_options.merge(:action => action.to_s))
map.named_route("formatted_#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path}.:format;#{action}", route_options.merge(:action => action.to_s))
if action == :new
map.named_route("#{resource.name_prefix}new_#{resource.singular}", resource.new_path, route_options.merge(:action => "new"))
map.named_route("formatted_#{resource.name_prefix}new_#{resource.singular}", "#{resource.new_path}.:format", route_options.merge(:action => "new"))
else
map.named_route("#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path};#{action}", route_options.merge(:action => action.to_s))
map.named_route("formatted_#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path}.:format;#{action}", route_options.merge(:action => action.to_s))
end
end
end
map.named_route("#{resource.name_prefix}new_#{resource.singular}", resource.new_path, :action => "new", :conditions => { :method => :get })
map.named_route("formatted_#{resource.name_prefix}new_#{resource.singular}", "#{resource.new_path}.:format", :action => "new", :conditions => { :method => :get })
end
def map_member_actions(map, resource)
......
......@@ -17,11 +17,11 @@ def test_should_arrange_actions
:member => { :rss => :get, :atom => :get, :upload => :post, :fix => :post },
:new => { :preview => :get, :draft => :get })
assert_resource_methods [:rss], resource, :collection, :get
assert_resource_methods [:csv, :reorder], resource, :collection, :post
assert_resource_methods [:edit, :rss, :atom], resource, :member, :get
assert_resource_methods [:upload, :fix], resource, :member, :post
assert_resource_methods [:preview, :draft], resource, :new, :get
assert_resource_methods [:rss], resource, :collection, :get
assert_resource_methods [:csv, :reorder], resource, :collection, :post
assert_resource_methods [:edit, :rss, :atom], resource, :member, :get
assert_resource_methods [:upload, :fix], resource, :member, :post
assert_resource_methods [:new, :preview, :draft], resource, :new, :get
end
def test_default_restful_routes
......@@ -122,6 +122,24 @@ def test_with_new_action
end
end
def test_override_new_method
with_restful_routing :messages do
assert_restful_routes_for :messages do |options|
assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get)
assert_raises(ActionController::RoutingError) do
ActionController::Routing::Routes.recognize_path("/messages/new", :method => :post)
end
end
end
with_restful_routing :messages, :new => { :new => :any } do
assert_restful_routes_for :messages do |options|
assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :post)
assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get)
end
end
end
def test_nested_restful_routes
with_routing do |set|
set.draw do |map|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册