When/Where do I use nested resources?
I have 2 classes in my rails app. App, and User. A User has Apps, which they have edit permission over.
I also want any user to be able to list ALL apps, whether or not they have permission.
That means the apps need to be accessed two ways. 1) /Users/1/Apps (This would be all the user's apps) 2) /Apps (This would be all recent apps 开发者_开发知识库in the system)
My question is, how do i set up routing for this reasource. Do I list it twice in routes? One as a standalone resource, and another nested under resource?
Do i keep the flat list, and pass a querystring with user Id?
Thoughts?
put this in your routes
resources :apps
resources :users do
resources :apps
end
also, for authorizations, I can recommend an awesome gem, cancan
I would go for your first option, as they are 2 different uses, one is the apps editable by the user, versus all the apps.
精彩评论