public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Add support for shallow nesting of routes. [#838 state:resolved]

Adds :shallow option to resource route definition. If true, paths for nested
resources which reference a specific member (ie. those with an :id parameter)
will not use the parent path prefix or name prefix.

Example :

map.resources :users, :shallow => true do |user|
  user.resources :posts
end

* GET /users/1/posts (maps to PostsController#index action as usual)
  named route "user_posts" is added as usual.

* GET /posts/2 (maps to PostsController#show action as if it were not nested)
  Additionally, named route "post" is added too.
lifo (author)
Sat Aug 30 06:58:16 -0700 2008
commit  83c6ba18899a9f797d79726ca0078bdf618ec3d4
tree    6a5d99003c58f1eda9477e0ffee197227705f09a
parent  be4ae1f5264d6593e9dec479af4503c4bde2877e
...
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
0
@@ -1,5 +1,19 @@
0
 *Edge*
0
 
0
+* Add support for shallow nesting of routes. #838 [S. Brent Faulkner]
0
+
0
+  Example :
0
+
0
+  map.resources :users, :shallow => true do |user|
0
+    user.resources :posts
0
+  end
0
+
0
+  - GET /users/1/posts (maps to PostsController#index action as usual)
0
+    named route "user_posts" is added as usual.
0
+
0
+  - GET /posts/2 (maps to PostsController#show action as if it were not nested)
0
+    Additionally, named route "post" is added too.
0
+
0
 * Added button_to_remote helper.  #3641 [Donald Piret, Tarmo Tänav]
0
 
0
 * Deprecate render_component. Please use render_component plugin from http://github.com/rails/render_component/tree/master [Pratik]
...
85
86
87
 
 
 
 
88
89
 
90
91
92
93
 
 
 
 
 
94
95
96
97
 
98
99
100
...
141
142
143
 
 
144
145
146
...
318
319
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
322
323
...
443
444
445
446
 
447
448
449
...
460
461
462
463
 
464
465
466
467
468
 
 
469
470
471
472
473
 
 
474
 
475
476
477
 
 
 
 
 
 
 
 
 
 
 
 
 
478
479
480
...
530
531
532
533
 
534
535
536
537
538
539
 
540
541
542
...
579
580
581
582
583
 
...
85
86
87
88
89
90
91
92
 
93
94
95
96
 
97
98
99
100
101
102
103
104
 
105
106
107
108
...
149
150
151
152
153
154
155
156
...
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
...
478
479
480
 
481
482
483
484
...
495
496
497
 
498
499
500
501
502
503
504
505
506
507
508
 
 
509
510
511
512
513
 
 
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
...
579
580
581
 
582
583
584
585
586
587
 
588
589
590
591
...
628
629
630
 
631
632
0
@@ -85,16 +85,24 @@ module ActionController
0
         @new_path  ||= "#{path}/#{new_action}"
0
       end
0
 
0
+      def shallow_path_prefix
0
+        @shallow_path_prefix ||= "#{path_prefix unless @options[:shallow]}"
0
+      end
0
+
0
       def member_path
0
-        @member_path ||= "#{path}/:id"
0
+        @member_path ||= "#{shallow_path_prefix}/#{path_segment}/:id"
0
       end
0
 
0
       def nesting_path_prefix
0
-        @nesting_path_prefix ||= "#{path}/:#{singular}_id"
0
+        @nesting_path_prefix ||= "#{shallow_path_prefix}/#{path_segment}/:#{singular}_id"
0
+      end
0
+
0
+      def shallow_name_prefix
0
+        @shallow_name_prefix ||= "#{name_prefix unless @options[:shallow]}"
0
       end
0
 
0
       def nesting_name_prefix
0
-        "#{name_prefix}#{singular}_"
0
+        "#{shallow_name_prefix}#{singular}_"
0
       end
0
 
0
       def action_separator
0
@@ -141,6 +149,8 @@ module ActionController
0
         super
0
       end
0
 
0
+      alias_method :shallow_path_prefix, :path_prefix
0
+      alias_method :shallow_name_prefix, :name_prefix
0
       alias_method :member_path,         :path
0
       alias_method :nesting_path_prefix, :path
0
     end
0
@@ -318,6 +328,31 @@ module ActionController
0
     #   comments_url(@article)
0
     #   comment_url(@article, @comment)
0
     #
0
+    # * <tt>:shallow</tt> - If true, paths for nested resources which reference a specific member
0
+    #   (ie. those with an :id parameter) will not use the parent path prefix or name prefix.
0
+    #
0
+    # The <tt>:shallow</tt> option is inherited by any nested resource(s).
0
+    #
0
+    # For example, 'users', 'posts' and 'comments' all use shallow paths with the following nested resources:
0
+    #
0
+    #   map.resources :users, :shallow => true do |user|
0
+    #     user.resources :posts do |post|
0
+    #       post.resources :comments
0
+    #     end
0
+    #   end
0
+    #   # --> GET /users/1/posts (maps to the PostsController#index action as usual)
0
+    #   #     also adds the usual named route called "user_posts"
0
+    #   # --> GET /posts/2 (maps to the PostsController#show action as if it were not nested)
0
+    #   #     also adds the named route called "post"
0
+    #   # --> GET /posts/2/comments (maps to the CommentsController#index action)
0
+    #   #     also adds the named route called "post_comments"
0
+    #   # --> GET /comments/2 (maps to the CommentsController#show action as if it were not nested)
0
+    #   #     also adds the named route called "comment"
0
+    #
0
+    # You may also use <tt>:shallow</tt> in combination with the +has_one+ and +has_many+ shorthand notations like:
0
+    #
0
+    #   map.resources :users, :has_many => { :posts => :comments }, :shallow => true
0
+    #
0
     # If <tt>map.resources</tt> is called with multiple resources, they all get the same options applied.
0
     #
0
     # Examples:
0
@@ -443,7 +478,7 @@ module ActionController
0
           map_associations(resource, options)
0
 
0
           if block_given?
0
-            with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], &block)
0
+            with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], :shallow => options[:shallow], &block)
0
           end
0
         end
0
       end
0
@@ -460,21 +495,35 @@ module ActionController
0
           map_associations(resource, options)
0
 
0
           if block_given?
0
-            with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], &block)
0
+            with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], :shallow => options[:shallow], &block)
0
           end
0
         end
0
       end
0
 
0
       def map_associations(resource, options)
0
+        map_has_many_associations(resource, options.delete(:has_many), options) if options[:has_many]
0
+
0
         path_prefix = "#{options.delete(:path_prefix)}#{resource.nesting_path_prefix}"
0
         name_prefix = "#{options.delete(:name_prefix)}#{resource.nesting_name_prefix}"
0
 
0
-        Array(options[:has_many]).each do |association|
0
-          resources(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => options[:namespace])
0
+        Array(options[:has_one]).each do |association|
0
+          resource(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => options[:namespace], :shallow => options[:shallow])
0
         end
0
+      end
0
 
0
-        Array(options[:has_one]).each do |association|
0
-          resource(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => options[:namespace])
0
+      def map_has_many_associations(resource, associations, options)
0
+        case associations
0
+        when Hash
0
+          associations.each do |association,has_many|
0
+            map_has_many_associations(resource, association, options.merge(:has_many => has_many))
0
+          end
0
+        when Array
0
+          associations.each do |association|
0
+            map_has_many_associations(resource, association, options)
0
+          end
0
+        when Symbol, String
0
+          resources(associations, :path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], :shallow => options[:shallow], :has_many => options[:has_many])
0
+        else
0
         end
0
       end
0
 
0
@@ -530,13 +579,13 @@ module ActionController
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.shallow_name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
0
             end
0
           end
0
         end
0
 
0
         show_action_options = action_options_for("show", resource)
0
-        map_named_routes(map, "#{resource.name_prefix}#{resource.singular}", resource.member_path, show_action_options)
0
+        map_named_routes(map, "#{resource.shallow_name_prefix}#{resource.singular}", resource.member_path, show_action_options)
0
 
0
         update_action_options = action_options_for("update", resource)
0
         map_unnamed_routes(map, resource.member_path, update_action_options)
0
@@ -579,4 +628,4 @@ end
0
 
0
 class ActionController::Routing::RouteSet::Mapper
0
   include ActionController::Resources
0
-end
0
\ No newline at end of file
0
+end
...
379
380
381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
383
384
...
429
430
431
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
433
434
...
440
441
442
 
 
 
 
 
 
 
 
 
 
 
443
444
445
...
744
745
746
 
 
 
 
 
 
 
747
748
749
...
751
752
753
754
755
 
 
 
 
756
757
758
...
760
761
762
763
764
765
766
 
 
 
 
 
767
768
769
...
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
 
 
 
 
 
 
 
 
 
 
 
 
786
787
788
...
798
799
800
 
 
 
 
 
 
 
801
802
803
804
805
806
807
 
 
 
808
 
809
810
811
...
814
815
816
817
818
819
820
 
 
 
 
821
822
823
824
825
 
 
 
 
826
827
828
...
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
...
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
...
806
807
808
809
810
811
812
813
814
815
816
817
818
...
820
821
822
 
 
823
824
825
826
827
828
829
...
831
832
833
 
 
834
835
836
837
838
839
840
841
842
843
...
845
846
847
 
 
 
 
 
 
 
 
 
 
 
 
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
...
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
 
888
889
890
891
892
893
894
895
...
898
899
900
 
 
 
 
901
902
903
904
905
 
 
 
 
906
907
908
909
910
911
912
0
@@ -379,6 +379,31 @@ class ResourcesTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+  def test_shallow_nested_restful_routes
0
+    with_routing do |set|
0
+      set.draw do |map|
0
+        map.resources :threads, :shallow => true do |map|
0
+          map.resources :messages do |map|
0
+            map.resources :comments
0
+          end
0
+        end
0
+      end
0
+
0
+      assert_simply_restful_for :threads,
0
+        :shallow => true
0
+      assert_simply_restful_for :messages,
0
+        :name_prefix => 'thread_',
0
+        :path_prefix => 'threads/1/',
0
+        :shallow => true,
0
+        :options => { :thread_id => '1' }
0
+      assert_simply_restful_for :comments,
0
+        :name_prefix => 'message_',
0
+        :path_prefix => 'messages/2/',
0
+        :shallow => true,
0
+        :options => { :message_id => '2' }
0
+    end
0
+  end
0
+
0
   def test_restful_routes_dont_generate_duplicates
0
     with_restful_routing :messages do
0
       routes = ActionController::Routing::Routes.routes
0
@@ -429,6 +454,32 @@ class ResourcesTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+  def test_resources_has_many_hash_should_become_nested_resources
0
+    with_routing do |set|
0
+      set.draw do |map|
0
+        map.resources :threads, :has_many => { :messages => [ :comments, { :authors => :threads } ] }
0
+      end
0
+
0
+      assert_simply_restful_for :threads
0
+      assert_simply_restful_for :messages, :name_prefix => "thread_", :path_prefix => 'threads/1/', :options => { :thread_id => '1' }
0
+      assert_simply_restful_for :comments, :name_prefix => "thread_message_", :path_prefix => 'threads/1/messages/1/', :options => { :thread_id => '1', :message_id => '1' }
0
+      assert_simply_restful_for :authors,  :name_prefix => "thread_message_", :path_prefix => 'threads/1/messages/1/', :options => { :thread_id => '1', :message_id => '1' }
0
+      assert_simply_restful_for :threads,  :name_prefix => "thread_message_author_", :path_prefix => 'threads/1/messages/1/authors/1/', :options => { :thread_id => '1', :message_id => '1', :author_id => '1' }
0
+    end
0
+  end
0
+
0
+  def test_shallow_resource_has_many_should_become_shallow_nested_resources
0
+    with_routing do |set|
0
+      set.draw do |map|
0
+        map.resources :messages, :has_many => [ :comments, :authors ], :shallow => true
0
+      end
0
+
0
+      assert_simply_restful_for :messages, :shallow => true
0
+      assert_simply_restful_for :comments, :name_prefix => "message_", :path_prefix => 'messages/1/', :shallow => true, :options => { :message_id => '1' }
0
+      assert_simply_restful_for :authors,  :name_prefix => "message_", :path_prefix => 'messages/1/', :shallow => true, :options => { :message_id => '1' }
0
+    end
0
+  end
0
+
0
   def test_resource_has_one_should_become_nested_resources
0
     with_routing do |set|
0
       set.draw do |map|
0
@@ -440,6 +491,17 @@ class ResourcesTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+  def test_shallow_resource_has_one_should_become_shallow_nested_resources
0
+    with_routing do |set|
0
+      set.draw do |map|
0
+        map.resources :messages, :has_one => :logo, :shallow => true
0
+      end
0
+
0
+      assert_simply_restful_for :messages, :shallow => true
0
+      assert_singleton_restful_for :logo, :name_prefix => 'message_', :path_prefix => 'messages/1/', :shallow => true, :options => { :message_id => '1' }
0
+    end
0
+  end
0
+
0
   def test_singleton_resource_with_member_action
0
     [:put, :post].each do |method|
0
       with_singleton_resources :account, :member => { :reset => method } do
0
@@ -744,6 +806,13 @@ class ResourcesTest < Test::Unit::TestCase
0
       options[:options] ||= {}
0
       options[:options][:controller] = options[:controller] || controller_name.to_s
0
 
0
+      if options[:shallow]
0
+        options[:shallow_options] ||= {}
0
+        options[:shallow_options][:controller] = options[:options][:controller]
0
+      else
0
+        options[:shallow_options] = options[:options]
0
+      end
0
+
0
       new_action    = ActionController::Base.resources_path_names[:new] || "new"
0
       edit_action   = ActionController::Base.resources_path_names[:edit] || "edit"
0
       if options[:path_names]
0
@@ -751,8 +820,10 @@ class ResourcesTest < Test::Unit::TestCase
0
         edit_action = options[:path_names][:edit] if options[:path_names][:edit]
0
       end
0
 
0
-      collection_path            = "/#{options[:path_prefix]}#{options[:as] || controller_name}"
0
-      member_path                = "#{collection_path}/1"
0
+      path                       = "#{options[:as] || controller_name}"
0
+      collection_path            = "/#{options[:path_prefix]}#{path}"
0
+      shallow_path               = "/#{options[:path_prefix] unless options[:shallow]}#{path}"
0
+      member_path                = "#{shallow_path}/1"
0
       new_path                   = "#{collection_path}/#{new_action}"
0
       edit_member_path           = "#{member_path}/#{edit_action}"
0
       formatted_edit_member_path = "#{member_path}/#{edit_action}.xml"
0
@@ -760,10 +831,13 @@ class ResourcesTest < Test::Unit::TestCase
0
       with_options(options[:options]) do |controller|
0
         controller.assert_routing collection_path,            :action => 'index'
0
         controller.assert_routing new_path,                   :action => 'new'
0
-        controller.assert_routing member_path,                :action => 'show', :id => '1'
0
-        controller.assert_routing edit_member_path,           :action => 'edit', :id => '1'
0
         controller.assert_routing "#{collection_path}.xml",   :action => 'index',            :format => 'xml'
0
         controller.assert_routing "#{new_path}.xml",          :action => 'new',              :format => 'xml'
0
+      end
0
+
0
+      with_options(options[:shallow_options]) do |controller|
0
+        controller.assert_routing member_path,                :action => 'show', :id => '1'
0
+        controller.assert_routing edit_member_path,           :action => 'edit', :id => '1'
0
         controller.assert_routing "#{member_path}.xml",       :action => 'show', :id => '1', :format => 'xml'
0
         controller.assert_routing formatted_edit_member_path, :action => 'edit', :id => '1', :format => 'xml'
0
       end
0
@@ -771,18 +845,18 @@ class ResourcesTest < Test::Unit::TestCase
0
       assert_recognizes(options[:options].merge(:action => 'index'),               :path => collection_path,  :method => :get)
0
       assert_recognizes(options[:options].merge(:action => 'new'),                 :path => new_path,         :method => :get)
0
       assert_recognizes(options[:options].merge(:action => 'create'),              :path => collection_path,  :method => :post)
0
-      assert_recognizes(options[:options].merge(:action => 'show',    :id => '1'), :path => member_path,      :method => :get)
0
-      assert_recognizes(options[:options].merge(:action => 'edit',    :id => '1'), :path => edit_member_path, :method => :get)
0
-      assert_recognizes(options[:options].merge(:action => 'update',  :id => '1'), :path => member_path,      :method => :put)
0
-      assert_recognizes(options[:options].merge(:action => 'destroy', :id => '1'), :path => member_path,      :method => :delete)
0
-
0
-      assert_recognizes(options[:options].merge(:action => 'index',               :format => 'xml'), :path => "#{collection_path}.xml",   :method => :get)
0
-      assert_recognizes(options[:options].merge(:action => 'new',                 :format => 'xml'), :path => "#{new_path}.xml",          :method => :get)
0
-      assert_recognizes(options[:options].merge(:action => 'create',              :format => 'xml'), :path => "#{collection_path}.xml",   :method => :post)
0
-      assert_recognizes(options[:options].merge(:action => 'show',    :id => '1', :format => 'xml'), :path => "#{member_path}.xml",       :method => :get)
0
-      assert_recognizes(options[:options].merge(:action => 'edit',    :id => '1', :format => 'xml'), :path => formatted_edit_member_path, :method => :get)
0
-      assert_recognizes(options[:options].merge(:action => 'update',  :id => '1', :format => 'xml'), :path => "#{member_path}.xml",       :method => :put)
0
-      assert_recognizes(options[:options].merge(:action => 'destroy', :id => '1', :format => 'xml'), :path => "#{member_path}.xml",       :method => :delete)
0
+      assert_recognizes(options[:shallow_options].merge(:action => 'show',    :id => '1'), :path => member_path,      :method => :get)
0
+      assert_recognizes(options[:shallow_options].merge(:action => 'edit',    :id => '1'), :path => edit_member_path, :method => :get)
0
+      assert_recognizes(options[:shallow_options].merge(:action => 'update',  :id => '1'), :path => member_path,      :method => :put)
0
+      assert_recognizes(options[:shallow_options].merge(:action => 'destroy', :id => '1'), :path => member_path,      :method => :delete)
0
+
0
+      assert_recognizes(options[:options].merge(:action => 'index',  :format => 'xml'), :path => "#{collection_path}.xml",   :method => :get)
0
+      assert_recognizes(options[:options].merge(:action => 'new',    :format => 'xml'), :path => "#{new_path}.xml",          :method => :get)
0
+      assert_recognizes(options[:options].merge(:action => 'create', :format => 'xml'), :path => "#{collection_path}.xml",   :method => :post)
0
+      assert_recognizes(options[:shallow_options].merge(:action => 'show',    :id => '1', :format => 'xml'), :path => "#{member_path}.xml",       :method => :get)
0
+      assert_recognizes(options[:shallow_options].merge(:action => 'edit',    :id => '1', :format => 'xml'), :path => formatted_edit_member_path, :method => :get)
0
+      assert_recognizes(options[:shallow_options].merge(:action => 'update',  :id => '1', :format => 'xml'), :path => "#{member_path}.xml",       :method => :put)
0
+      assert_recognizes(options[:shallow_options].merge(:action => 'destroy', :id => '1', :format => 'xml'), :path => "#{member_path}.xml",       :method => :delete)
0
 
0
       yield options[:options] if block_given?
0
     end
0
@@ -798,14 +872,24 @@ class ResourcesTest < Test::Unit::TestCase
0
       options[:options] ||= {}
0
       options[:options][:controller] = options[:controller] || controller_name.to_s
0
 
0
+      if options[:shallow]
0
+        options[:shallow_options] ||= {}
0
+        options[:shallow_options][:controller] = options[:options][:controller]
0
+      else
0
+        options[:shallow_options] = options[:options]
0
+      end
0
+
0
       @controller = "#{options[:options][:controller].camelize}Controller".constantize.new
0
       @request    = ActionController::TestRequest.new
0
       @response   = ActionController::TestResponse.new
0
       get :index, options[:options]
0
       options[:options].delete :action
0
 
0
-      full_prefix = "/#{options[:path_prefix]}#{options[:as] || controller_name}"
0
+      path = "#{options[:as] || controller_name}"
0
+      shallow_path = "/#{options[:path_prefix] unless options[:shallow]}#{path}"
0
+      full_path = "/#{options[:path_prefix]}#{path}"
0
       name_prefix = options[:name_prefix]
0
+      shallow_prefix = "#{options[:name_prefix] unless options[:shallow]}"
0
 
0
       new_action  = "new"
0
       edit_action = "edit"
0
@@ -814,15 +898,15 @@ class ResourcesTest < Test::Unit::TestCase
0
         edit_action = options[:path_names][:edit] || "edit"
0
       end
0
 
0
-      assert_named_route "#{full_prefix}",            "#{name_prefix}#{controller_name}_path",              options[:options]
0
-      assert_named_route "#{full_prefix}.xml",        "formatted_#{name_prefix}#{controller_name}_path",    options[:options].merge(            :format => 'xml')
0
-      assert_named_route "#{full_prefix}/1",          "#{name_prefix}#{singular_name}_path",                options[:options].merge(:id => '1')
0
-      assert_named_route "#{full_prefix}/1.xml",      "formatted_#{name_prefix}#{singular_name}_path",      options[:options].merge(:id => '1', :format => 'xml')
0
+      assert_named_route "#{full_path}", "#{name_prefix}#{controller_name}_path", options[:options]
0
+      assert_named_route "#{full_path}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge(:format => 'xml')
0
+      assert_named_route "#{shallow_path}/1", "#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1')
0
+      assert_named_route "#{shallow_path}/1.xml", "formatted_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1', :format => 'xml')
0
 
0
-      assert_named_route "#{full_prefix}/#{new_action}",        "new_#{name_prefix}#{singular_name}_path",            options[:options]
0
-      assert_named_route "#{full_prefix}/#{new_action}.xml",    "formatted_new_#{name_prefix}#{singular_name}_path",  options[:options].merge(            :format => 'xml')
0
-      assert_named_route "#{full_prefix}/1/#{edit_action}",     "edit_#{name_prefix}#{singular_name}_path",           options[:options].merge(:id => '1')
0
-      assert_named_route "#{full_prefix}/1/#{edit_action}.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
0
+      assert_named_route "#{full_path}/#{new_action}", "new_#{name_prefix}#{singular_name}_path", options[:options]
0
+      assert_named_route "#{full_path}/#{new_action}.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge(:format => 'xml')
0
+      assert_named_route "#{shallow_path}/1/#{edit_action}", "edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1')
0
+      assert_named_route "#{shallow_path}/1/#{edit_action}.xml", "formatted_edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1', :format => 'xml')
0
 
0
       yield options[:options] if block_given?
0
     end

Comments

acf Sun Sep 07 21:52:20 -0700 2008

AWESOME. Does this already exist as a plugin? If not, I might have a crack at it.

acf Sun Sep 07 21:53:45 -0700 2008

AWESOME. Does this already exist as a plugin? If not, I might have a crack at it.

acf Sun Sep 07 21:55:11 -0700 2008

argh. sorry for the double post, timed out on the first.

shaokun Wed Mar 04 19:35:05 -0800 2009

This is cool! But new_{resource}_path is not supported for the nested resource, can we add that too?