I have a design question where I would appreciate a thoughtful
Let's say you have a simple application (for example's sake) that has
a User, Company and Theme model. A Company `has_one` Theme and
Administrators (a User) can fully manage Companies and Themes - the
whole REST stack, in addition to a few other actions too.
Administrators are expected to do things to Companies and themes that
other user roles cannot do.
We also have a Company role. This role can edit their own Company, as
well as select a Theme from the ones the admin-user added as nice
defaults, or they can just make their own theme.
Now, here we have some non-trivial design choices, and I would like to
know what the best-practice is.
In Rails, it makes sense to have
`resources :users, :companies, :themes` for the administrators and
probably `resource :company, :theme, :users` for the Company users.
But of course, we run into some naming conflicts here - both singular
and plural - so we might want to try something like
`resource :my_company, :my_theme, :my_users` to separate them? Or is
there a better solution?
Furthermore, a theme is just a component of a company, so maybe we
want to nest them?
:resource :my_company do
This works okay, but it could be confusing as to which UsersController
we are referring to... no? This is really sticky and I would love to
know how to deal with this. Do you have 1 controller, or 2? What do
you name them?
But then I look at the url, and it's kind of silly:
I guess it could be worse.
Company users also might want the list of themes via ajax, so is it
correct for them to call:
Is this how to approach this situation, or is there a better way?
Also, what should your directory structure look? Should you have
controllers separated by user role?
Or is there better ways to handle this?
I would really appreciate a thoughtful response on this. Thanks!