public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Accept an array of method symbols for collection/member actions of resources

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
brennandunn (author)
Thu Aug 28 04:35:00 -0700 2008
jeremy (committer)
Thu Aug 28 12:23:39 -0700 2008
commit  7bdd5b768e51f74fa437d1cc8f3c36643364c4fe
tree    302fa46da10fdd0331ec751aa02134d192653c2c
parent  db22c89543f45d7f27847003af949afa21cb6fa1
...
238
239
240
241
242
 
 
 
243
244
245
...
480
481
482
483
484
 
 
 
 
485
486
487
...
521
522
523
524
 
 
525
526
527
 
 
528
529
 
 
530
531
532
...
238
239
240
 
 
241
242
243
244
245
246
...
481
482
483
 
 
484
485
486
487
488
489
490
...
524
525
526
 
527
528
529
 
 
530
531
532
 
533
534
535
536
537
0
@@ -238,8 +238,9 @@ module ActionController
0
     #
0
     # The +resources+ method accepts the following options to customize the resulting routes:
0
     # * <tt>:collection</tt> - Add named routes for other actions that operate on the collection.
0
-    #   Takes a hash of <tt>#{action} => #{method}</tt>, where method is <tt>:get</tt>/<tt>:post</tt>/<tt>:put</tt>/<tt>:delete</tt>
0
-    #   or <tt>:any</tt> if the method does not matter.  These routes map to a URL like /messages/rss, with a route of +rss_messages_url+.
0
+    #   Takes a hash of <tt>#{action} => #{method}</tt>, where method is <tt>:get</tt>/<tt>:post</tt>/<tt>:put</tt>/<tt>:delete</tt>,
0
+    #   an array of any of the previous, or <tt>:any</tt> if the method does not matter.
0
+    #   These routes map to a URL like /messages/rss, with a route of +rss_messages_url+.
0
     # * <tt>:member</tt> - Same as <tt>:collection</tt>, but for actions that operate on a specific member.
0
     # * <tt>:new</tt> - Same as <tt>:collection</tt>, but for actions that operate on the new resource action.
0
     # * <tt>:controller</tt> - Specify the controller name for the routes.
0
@@ -480,8 +481,10 @@ module ActionController
0
       def map_collection_actions(map, resource)
0
         resource.collection_methods.each do |method, actions|
0
           actions.each do |action|
0
-            action_options = action_options_for(action, resource, method)
0
-            map_named_routes(map, "#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options)
0
+            [method].flatten.each do |m|
0
+              action_options = action_options_for(action, resource, m)
0
+              map_named_routes(map, "#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options)
0
+            end
0
           end
0
         end
0
       end
0
@@ -521,12 +524,14 @@ module ActionController
0
       def map_member_actions(map, resource)
0
         resource.member_methods.each do |method, actions|
0
           actions.each do |action|
0
-            action_options = action_options_for(action, resource, method)
0
+            [method].flatten.each do |m|
0
+              action_options = action_options_for(action, resource, m)
0
 
0
-            action_path = resource.options[:path_names][action] if resource.options[:path_names].is_a?(Hash)
0
-            action_path ||= Base.resources_path_names[action] || action
0
+              action_path = resource.options[:path_names][action] if resource.options[:path_names].is_a?(Hash)
0
+              action_path ||= Base.resources_path_names[action] || action
0
 
0
-            map_named_routes(map, "#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
0
+              map_named_routes(map, "#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
0
+            end
0
           end
0
         end
0
 
...
264
265
266
 
 
 
 
 
 
 
 
 
 
 
 
 
267
268
269
...
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
0
@@ -264,6 +264,19 @@ class ResourcesTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+  def test_array_as_collection_or_member_method_value
0
+    with_restful_routing :messages, :collection => { :search => [:get, :post] }, :member => { :toggle => [:get, :post] } do
0
+      assert_restful_routes_for :messages do |options|
0
+        [:get, :post].each do |method|
0
+          assert_recognizes(options.merge(:action => 'search'), :path => "/messages/search", :method => method)
0
+        end
0
+        [:get, :post].each do |method|
0
+          assert_recognizes(options.merge(:action => 'toggle', :id => '1'), :path => '/messages/1/toggle', :method => method)
0
+        end
0
+      end
0
+    end
0
+  end
0
+
0
   def test_with_new_action
0
     with_restful_routing :messages, :new => { :preview => :post } do
0
       preview_options = {:action => 'preview'}

Comments