Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove namespace from nested resource

I have a namspaced resource, but I'd like a specific nested resource to route to a non-namespaced controller, e.g.:

namespace :admin do
  resources :posts do # /admin/posts => Admin::PostsController
    resources :audits, only: [:index] # /admin/posts/1/audits => AuditsController
  end
end

The guides state that:

If you need to use a different controller namespace inside a namespace block you can specify an absolute controller path, e.g: get '/foo' => '/foo#index'.

but this results in "wrong constant name" because rails tries to convert admin//audits in to a constant.

like image 948
Mike Campbell Avatar asked Apr 28 '26 14:04

Mike Campbell


1 Answers

I ended up just splitting it out completely and doing

get 'admin/users/:user_id/audits', to: 'audits#index'

Still don't really understand the quote from the guides, I assume it must be incorrect.

like image 108
Mike Campbell Avatar answered Apr 30 '26 03:04

Mike Campbell