3

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.

Mike Campbell
  • 7,921
  • 2
  • 38
  • 51
  • Why don't you take the resource you want out? – kurenn Jan 05 '15 at 18:21
  • could you provide an example? I want the route nested, so I'm not sure what you recommend I do. – Mike Campbell Jan 06 '15 at 09:26
  • Well if you just let something like this ` resources :posts do # /admin/posts => Admin::PostsController resources :audits, only: [:index] # /admin/posts/1/audits => AuditsController end` it will create routes but omitting the admin namespace, is that what you want. You can have both routes – kurenn Jan 06 '15 at 20:16
  • yeah, but I want the namespace for the posts resource. – Mike Campbell Jan 07 '15 at 09:19

1 Answers1

2

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.

Mike Campbell
  • 7,921
  • 2
  • 38
  • 51
  • I had a similar problem and found this answer helpful: https://stackoverflow.com/a/26926185/23723 – Matt Oct 24 '17 at 11:29