I have routes like this:
resources :users do
resources :projects
end
I would like to be able to access routes like this:
/users/1/projects/1
and
/projects/1
Is this possible? How would I set this up? I’m having and issue in my app where we would like to have users able to see both their own projects via /users/:id/projects/:id but also on other pages we’d like to just see all the projects created, like this /projects or a project and an id, like this /projects/:id. I feel like I’m missing something, should I just get rid of the nested routes? Or can I have both.
You can have both. Just add
resources :projectsto your routes.rb.Then, in your ProjectsController you will have to do:
I’m assuming your authentication system provides with
current_usermethod for your controllers (as most of them do)