From 73a8d7393f842d4030561cef20fcf0ec9d52e1b9 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 13 Sep 2006 04:04:19 +0000 Subject: Make sure that formatted routes for all verbs are created. Still needs to resolve two failing tests after this refactoring [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5096 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/resources.rb | 34 +++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'actionpack/lib/action_controller/resources.rb') diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index 1c59a23c96..dcc4c19c90 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -45,11 +45,7 @@ module ActionController end def add_default_actions - add_default_action(collection_methods, :post, :create) - add_default_action(member_methods, :get, :edit) - add_default_action(member_methods, :put, :update) - add_default_action(member_methods, :delete, :destroy) - add_default_action(new_methods, :get, :new) + add_default_action(member_methods, :get, :edit) end def set_prefixes @@ -250,24 +246,26 @@ module ActionController map.connect(resource.path, route_options.merge(:action => primary)) map.connect("#{resource.path}.:format", route_options.merge(:action => primary)) end - - map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, :action => "index", :conditions => { :method => :get }) - map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", :action => "index", :conditions => { :method => :get }) end + + map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, :action => "index", :conditions => { :method => :get }) + map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", :action => "index", :conditions => { :method => :get }) + + map.connect(resource.path, :action => "create", :conditions => { :method => :post }) + map.connect("#{resource.path}.:format", :action => "create", :conditions => { :method => :post }) end - + def map_new_actions(map, resource) resource.new_methods.each do |method, actions| route_options = requirements_for(method) actions.each do |action| - path = action == :new ? resource.new_path : "#{resource.new_path};#{action}" - name = "new_#{resource.singular}" - name = "#{action}_#{name}" unless action == :new - - map.named_route("#{resource.name_prefix}#{name}", path, route_options.merge(:action => action.to_s)) - map.named_route("formatted_#{resource.name_prefix}#{name}", action == :new ? "#{resource.new_path}.:format" : "#{resource.new_path}.:format;#{action}", route_options.merge(:action => action.to_s)) + 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 + + 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) @@ -285,6 +283,12 @@ module ActionController map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, :action => "show", :conditions => { :method => :get }) map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", :action => "show", :conditions => { :method => :get }) + + map.connect(resource.member_path, :action => "update", :conditions => { :method => :put }) + map.connect("#{resource.member_path}.:format", :action => "update", :conditions => { :method => :put }) + + map.connect(resource.member_path, :action => "destroy", :conditions => { :method => :delete }) + map.connect("#{resource.member_path}.:format", :action => "destroy", :conditions => { :method => :delete }) end def requirements_for(method) -- cgit v1.2.3