开发者

Routes question: what if I want both a resource to be nested and on its own?

Objective:

Be able to nest a resource, like records inside of users so that I can access /users/1/records to see all of the first users records. But I would also like to see /records to see all of the records ( or the new ones, or something like that ).

Problem

So I know I am missing something somewhere because that cannot be the way to do it. I know I can have like a static page or some other ro开发者_运维技巧ute for that, but I don't think that is very rails-y.

I would have users, so a user would see their page with their records, but also be able to browse records, so I assumed I would need a more general route for that.

Question

What is the appropriate way to browse a nested resource?

PS I have looked at things like this question, which almost address the problem, but deals with a static landing page for non logged in users, this is not what I am looking for.


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

resources :records

resources :users do
  resources :records
end

I think you'll need to do something in records's index controller to check if its called for some user or not.

UPD: Ok, checked it. Check for params[:user_id] in your index controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜