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.

4
  • Why don't you take the resource you want out? Commented Jan 5, 2015 at 18:21
  • could you provide an example? I want the route nested, so I'm not sure what you recommend I do. Commented Jan 6, 2015 at 9: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 Commented Jan 6, 2015 at 20:16
  • yeah, but I want the namespace for the posts resource. Commented Jan 7, 2015 at 9:19

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I had a similar problem and found this answer helpful: stackoverflow.com/a/26926185/23723

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.