The question of routes: what if I want the resource to be invested by itself?

Goal:

To be able to place a resource, for example, records inside users , so that I can access /users/1/records to see all the records of the first users. But I would also like to see /records to see all the records (either new or something like this).

Problem

So, I know that something is missing because it is impossible. I know that I may have a static page or some other route, but I don’t think it is very rails.

I would have users, so the user will see their page with their entries, but will also be able to view the entries, so I suggested that for this I would need a more general route.

Question

What is the appropriate way to view the attached resource?

PS I considered things like this question that almost solve the problem, but deal with a static landing page for non-registered users, this is not what I'm looking for.

+4
source share
1 answer

Not sure how to handle this route later on in the controllers (never tried), but something like this should work:

 resources :records resources :users do resources :records end 

I think you need to do something in the index controller to check if some user is called or not.

UPD: Ok, checked. Check the [: user_id] parameters in your index controller.

+2
source

All Articles