[devise] How to add nested routes to the users parent resource

441 views
Skip to first unread message

Kulgar

unread,
Sep 5, 2011, 5:21:30 AM9/5/11
to Devise
Hi everyone :)

I'd like to know how to add nested routes within the users parent
resource.

Thanks to this sort of code:

devise_for :users do
resources :posts
end

I would like to have these routes:

- GET /users/:id/posts
- GET /users/:id/posts/new
- POST /users/:id/posts
etc.

But the code above doesn't generate such a thing, I only get the
"normal routes" :
GET /posts
GET /posts/new
POST /posts
etc.

So I'd like to learn the correct way to add nested resources to users
using devise_for.

I came accross this discussion :
http://groups.google.com/group/plataformatec-devise/browse_thread/thread/8cbb5ac87ad08cff/f1a1b7af655789a6

Where this

resources :businesses do
devise_for :users
end

Generates somehow the routes I want but it doesn't seem to be a normal
behaviour nor the rails way.

Thanks for your help :)


Kulgar.

PS: It would be great to add this issue (when solved) to the "how to"
wiki of Devise on GIT Hub.

Kulgar

unread,
Sep 10, 2011, 5:35:43 AM9/10/11
to Devise
Anyone ? :)

I'm sure it's not as difficult as it seems to be but I can't find how
to solve this problem...

Alexandre Mello

unread,
Jul 4, 2013, 8:47:22 AM7/4/13
to plataforma...@googlegroups.com
I'm late but...

You can use CRUD to control de devise user: example. So you can use nested routes.
Reply all
Reply to author
Forward
0 new messages