Вопрос

Picking up Rails 3 for my next web app.

Basically I have a set of nested resources.

Users => Apps => Form

I spent some time earlier using sessions to hold an app_id so I could access that apps forms.

But I then discovered nested routes in Rails 3.... so which one is best? I might have another layer after Forms so it would be nested 3 or 4 times. I ran into this resource while reading rails guides http://weblog.jamisbuck.org/2007/2/5/nesting-resources and am on the fence about how to proceed.

Should I use the nested resources with rails or just start using sessions since I may have a large amount of nested resources?

Это было полезно?

Решение

A session is closed as soon as the user closes his browser. So if you want to store the app_id only temporarily and only for this currenct user, sessions are your friend.

If you want working permalinks and the link has nothing to do with the actual user, you should use the nestes resources.

E.g. users/1/apps/5/... if user 1 always has these apps you should not handle this with your sessions. If you want that only user 1 can access users/1/apps/5 you could handle this with sessions/cookies and your login-system.

If you worry about the length of the URLs because of the depth of the resources just keep an eye on what is understandable and easy to read. I don't know the aim of your web app, so I can't tell if it is reasonable to have 'form' as a resource of 'Apps'.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top