Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To Nest or Not to Nest?

Premise: Usually during preparation of a new Ruby on Rails App, I draw out models and relations regarding user navigations. Usually I hit a place where I need to ask myself, whether or not I should go beyond the usual "rule of thumb" of nesting no more 1 level deep. Sometimes I feel the need to nest, rather than creating another namespace route and duplicating work.
Here's an example:

Models: User, Company, Location
User has and belongs to many Companies (many to many)
User has and belongs to many Locations (many to many)
Company has and belongs to many Locations (many to many)

Routes:
1 level nesting
users/:user_id/companies/ - list all companies related to a user
users/:user_id/locations/ - list all locations related to a user
more than 1 level nesting
users/:user_id/companies/:company_id/locations/ - list all company-locations of a user

So, my question is whether or not it is appropriate to nest more than 1 level deep in RoR? Yes or no? And why?

like image 514
Anthony Avatar asked Oct 02 '08 20:10

Anthony


People also ask

Is nesting good in SCSS?

Nesting can be a good way to organize your Sass code. It can also lead to specificity problems if you nest too deeply. You don't have to look to far to find people who'll tell you how wonderful nesting is or how the universe might cave in on itself if you attempt to nest your code.

What is nesting in SCSS?

Nesting is combining of different logic structures. Using SASS, we can combine multiple CSS rules within one another. If you are using multiple selectors, then you can use one selector inside another to create compound selectors.

Can we do nesting in CSS?

When we use a CSS preprocessor like Sass or Less, we can nest a CSS style rule within another rule to write clean and understandable code. This nesting rule is not supported yet in native CSS. At the moment, it is a working draft and only available for discussion.

Does CSS support nesting of classes?

This module introduces the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule. This increases the modularity and maintainability of CSS stylesheets.


1 Answers

I tend to follow Jamis Buck's advice and never nest more than one level deep.

Edit: If you are going to nest more than 1 level I would check out the new shallow routes feature in Edge

like image 142
Mike Breen Avatar answered Sep 28 '22 00:09

Mike Breen