diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index c8ea4052f67be41e4945b15cfa938a78b070f8c6..2b22041b3b4b758109b67e05c7fe325b7bddf558 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,9 @@ +* Generate shallow paths for all children of shallow resources. + + Fixes #15783. + + *Seb Jacobs* + * JSONP responses are now rendered with the `text/javascript` content type when rendering through a `respond_to` block. @@ -177,5 +183,4 @@ *Tony Wooster* - Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/actionpack/CHANGELOG.md) for previous changes. diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 3774b625af6ba709fc212368bfb3532d5179d267..235a8406820055361542d79f008daf579a4db5ad 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1434,7 +1434,7 @@ def nested end with_scope_level(:nested) do - if shallow? && shallow_nesting_depth > 1 + if shallow? && shallow_nesting_depth >= 1 shallow_scope(parent_resource.nested_scope, nested_options) { yield } else scope(parent_resource.nested_scope, nested_options) { yield } diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 130f2b5b215725339d9b1f0a651db7b3218ae34f..78940ef6cc6eeb182fc749bf15f36e6b69988184 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2022,6 +2022,28 @@ def test_shallow_deeply_nested_resources assert_equal '/blogs/1/posts/2/comments/new', new_blog_post_comment_path(:blog_id => 1, :post_id => 2) end + def test_direct_children_of_shallow_resources + draw do + resources :blogs do + resources :posts, shallow: true do + resources :comments + end + end + end + + post '/posts/1/comments' + assert_equal 'comments#create', @response.body + assert_equal '/posts/1/comments', post_comments_path('1') + + get '/posts/2/comments/new' + assert_equal 'comments#new', @response.body + assert_equal '/posts/2/comments/new', new_post_comment_path('2') + + get '/posts/1/comments' + assert_equal 'comments#index', @response.body + assert_equal '/posts/1/comments', post_comments_path('1') + end + def test_shallow_nested_resources_within_scope draw do scope '/hello' do