On Fri, May 27, 2011 at 7:55 PM, egervari <ken.egerv...@gmail.com> wrote:

> I have a design question where I would appreciate a thoughtful
> response.
>
> 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
> `has_many` Users.
>
> 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.
>
> **PART 1**
>
> 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
>      :resource :theme
>      :resources :users
>    end
>
> 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:
>
>    http://myapp.com/my_company/my_theme/edit
>
> 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:
>
>    http://myapp.com/themes.json
>
> ?
>
> Is this how to approach this situation, or is there a better way?
>
> **PART 2**
>
> Also, what should your directory structure look? Should you have
> controllers separated by user role?
>
>    /app/controllers/admin/companies_controller.rb
>    /app/controllers/admin/themes_controller.rb
>    /app/controllers/admin/users_controller.rb
>    /app/controllers/company/my_company_controller.rb
>    /app/controllers/company/theme_controller.rb
>    /app/controllers/company/users_controller.rb
>
> Or is there better ways to handle this?
>

Look into namespacing your routes. So you could end up with the directory
structure above, and have it be clean like:

resources :company
resources :theme
resources :users

namespace :admin
   resources :company
   .....
end



>
> I would really appreciate a thoughtful response on this. Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to