Why is it considered a bad practice to have deeply nested resources?

Why is it considered bad to have routes defined as shown below, when that’s an accurate reflection of the structure of the application?

In some way, nested resources are a very good thing – you can ensure that the only records visible are scoped by the “parent association” (see how the addresses are limited to their parent person in the meaningful URL example).

But when you want to show a link to an individual comment, this deep nesting means that you’re going to have a giant URL to generate – including lots of knowledge about those parent objects user_group_playlist_comment_path(@user, @group, @playlist, @comment). You need to know all four objects just to generate a URL. Not just that, but your user needs to know the structure of your application in order to type in a URL (which is a rare occurrence nowadays, but the URL is still part of your user-interface).

A better alternative would be:

This means that you get some scoping protection (for example, you can only access a comment in the context of a playlist), but you’re not exposing your application structure to all and sundry – plus it’s trivial to generate a URL – playlist_comment_path(@playlist, @comment).

(Rails has an option for “shallow” routes, which short-cuts the generation of these routes. To be honest, I’ve never used it, but I can see that it’s a useful shorthand – sometimes I like things to be explicit though)