Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Usage of shallow inside of a namespace results in doubled namespaces in routes #12498

Closed
contentfree opened this Issue · 2 comments

4 participants

@contentfree

Given:

My::Application.routes.draw do
  namespace :admin do
    shallow do
      resources :users do
        resources :articles do
          resources :comments
        end
      end
    end
  end
end

Running rake routes results in entries:

   admin_article_comments GET    /admin/admin/articles/:article_id/comments(.:format)     admin/comments#index
                          POST   /admin/admin/articles/:article_id/comments(.:format)     admin/comments#create
new_admin_article_comment GET    /admin/admin/articles/:article_id/comments/new(.:format) admin/comments#new
       edit_admin_comment GET    /admin/admin/comments/:id/edit(.:format)                 admin/comments#edit
            admin_comment GET    /admin/admin/comments/:id(.:format)                      admin/comments#show
                          PATCH  /admin/admin/comments/:id(.:format)                      admin/comments#update
                          PUT    /admin/admin/comments/:id(.:format)                      admin/comments#update
                          DELETE /admin/admin/comments/:id(.:format)                      admin/comments#destroy
      admin_user_articles GET    /admin/admin/users/:user_id/articles(.:format)           admin/articles#index
                          POST   /admin/admin/users/:user_id/articles(.:format)           admin/articles#create
   new_admin_user_article GET    /admin/admin/users/:user_id/articles/new(.:format)       admin/articles#new
       edit_admin_article GET    /admin/admin/articles/:id/edit(.:format)                 admin/articles#edit
            admin_article GET    /admin/admin/articles/:id(.:format)                      admin/articles#show
                          PATCH  /admin/admin/articles/:id(.:format)                      admin/articles#update
                          PUT    /admin/admin/articles/:id(.:format)                      admin/articles#update
                          DELETE /admin/admin/articles/:id(.:format)                      admin/articles#destroy
              admin_users GET    /admin/users(.:format)                                   admin/users#index
                          POST   /admin/users(.:format)                                   admin/users#create
           new_admin_user GET    /admin/users/new(.:format)                               admin/users#new
          edit_admin_user GET    /admin/admin/users/:id/edit(.:format)                    admin/users#edit
               admin_user GET    /admin/admin/users/:id(.:format)                         admin/users#show
                          PATCH  /admin/admin/users/:id(.:format)                         admin/users#update
                          PUT    /admin/admin/users/:id(.:format)                         admin/users#update
                          DELETE /admin/admin/users/:id(.:format)                         admin/users#destroy

Almost all get the doubled-up /admin/admin.

Flipping the order of namespace and shallow appears to result in the expected behavior. It still feels like a bug (because you might not want to shallow everything in a namespace).

@contentfree

Another fix is:

My::Application.routes.draw do
  namespace :admin do
    resources :users, shallow: true do # <== Replace shallow method usage with option
      resources :articles do
        resources :comments
      end
    end
  end
end
@pixeltrix pixeltrix was assigned
@Kaermes

taking a look at this

@pixeltrix pixeltrix closed this issue from a commit
@pixeltrix pixeltrix Set the :shallow_path as each scope is generated
If we set :shallow_path when shallow is called it can result in incorrect
paths if the resource is inside a namespace because namespace itself sets
the :shallow_path option to the namespace path.

We fix this by removing the :shallow_path option from shallow as that should
only be turning shallow routes on and not otherwise affecting the scope.
To do this we need to treat the :shallow option to resources differently to
other scope options and move it to before the nested block is called.

This change also has the positive side effect of making the behavior of the
:shallow option consistent with the shallow method.

Fixes #12498.
462d7cb
@pixeltrix pixeltrix closed this in 462d7cb
@pixeltrix pixeltrix referenced this issue from a commit
@pixeltrix pixeltrix Set the :shallow_path as each scope is generated
If we set :shallow_path when shallow is called it can result in incorrect
paths if the resource is inside a namespace because namespace itself sets
the :shallow_path option to the namespace path.

We fix this by removing the :shallow_path option from shallow as that should
only be turning shallow routes on and not otherwise affecting the scope.
To do this we need to treat the :shallow option to resources differently to
other scope options and move it to before the nested block is called.

This change also has the positive side effect of making the behavior of the
:shallow option consistent with the shallow method.

Fixes #12498.

(cherry picked from commit 462d7cb)

Conflicts:
	actionpack/CHANGELOG.md
	actionpack/test/dispatch/routing_test.rb
ce671be
@pixeltrix pixeltrix referenced this issue from a commit
@pixeltrix pixeltrix Only use shallow nested scope when depth is > 1
By tracking the depth of resource nesting we can push the need for nested
shallow scoping to only those routes that are nested more than one deep.
This allows us to keep the fix for #12498 and fix the regression in #14224.

Fixes #14224.
dcc91a0
@pixeltrix pixeltrix referenced this issue from a commit
@pixeltrix pixeltrix Only use shallow nested scope when depth is > 1
By tracking the depth of resource nesting we can push the need for nested
shallow scoping to only those routes that are nested more than one deep.
This allows us to keep the fix for #12498 and fix the regression in #14224.

Fixes #14224.

(cherry picked from commit dcc91a0)
7de1a68
@pixeltrix pixeltrix referenced this issue from a commit
@pixeltrix pixeltrix Only use shallow nested scope when depth is > 1
By tracking the depth of resource nesting we can push the need for nested
shallow scoping to only those routes that are nested more than one deep.
This allows us to keep the fix for #12498 and fix the regression in #14224.

Fixes #14224.

(cherry picked from commit dcc91a0)
6adc92e
@ttosch ttosch referenced this issue from a commit
@pixeltrix pixeltrix Only use shallow nested scope when depth is > 1
By tracking the depth of resource nesting we can push the need for nested
shallow scoping to only those routes that are nested more than one deep.
This allows us to keep the fix for #12498 and fix the regression in #14224.

Fixes #14224.

(cherry picked from commit dcc91a0)
44c23af
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.