small medium large xlarge

09 Feb 2009, 19:29
William Hertling (23 posts)

If my model contains nested objects, what’s the right way to generate urls? For example, I have a wishlists, and wishitems. A wishitem belongs to a wishlist. My URLs should be formatted like this: “appname/wishlist/:id/wishitem/:id”, where the first :id is the id of the wishlist, and the second :id is the id of the wishitem.

How do I correctly specify a url of that type, whether for use in a form, or a redirect_to or a link_to call? Do I need to create named routes? And if I do, how do I distinguish between the first id and the second id, or does that happen automagically?

Thanks, Will

12 Feb 2009, 18:55
Sam Ruby (633 posts)

Short answer: appname/wishlist/:wishlist_id/wishitem/:id

Longer answer: see “Nested Resources” on pages 458-463 in B10.

You must be logged in to comment