Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I appreciate your desire to organize your codebase as I constantly have to convince myself not to take my default impulse to nest a resource or namespace a model. As there is no right answer to this question, I will just offer the reasons I use to convince myself not to.</p> <ul> <li>A resource lives in once place. <code>User.find(1)</code> should have a single locator (URL), which I like to call user_path. I like calling it user_path because of all the times that I have made myself call it admin_company_user_path([@company, @user]) which malaise makes in me each time I write it.</li> <li>That resource may render itself in different ways for different situations, like if the requester was an XHR or indicated that they would prefer German to English. Why is the header indicating that the user is an administrator any different?</li> <li>If I can make it look like the simplest examples in the rails/README, shouldn't I?</li> </ul> <p>At this point I would concede and end up with:</p> <pre><code>/app/controllers/companies_controller.rb /app/controllers/users_controller.rb /app/controllers/themes_controller.rb </code></pre> <p>And my routes.rb would have:</p> <pre><code>resources :users resources :companies resources :themes </code></pre> <p>I should also address how I would handle the thing that makes you want to separate them in the first place–a different view for each of the roles. In my ideal scenario, my decision would result in a <code>themes/_form.haml</code> that looks like:</p> <pre><code>= form.input :title if user_can_change_title? = form.input :theme if user_can_change_theme? </code></pre> <p>And the rest of the differences would handled in CSS, with perhaps a stylesheet for each role.</p> <p>In the less ideal scenario, I might be using:</p> <pre><code>= render :partial =&gt; "#{current_user.role}_form" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload