title: Rails 5 - nested controllers with routes
body: <p>I'm trying to make an app in Rails 5.</p>
  
  <p>In order to keep the file structure neat, I'm trying to make folders inside my controllers directory, that I can use to group similar resources.</p>
  
  <p>For example, I have:</p>
  
  <pre><code> app/controllers/users/users_controller.rb
  </code></pre>
  
  <p>I can then make my sessions controller nested inside the controllers/users director so that all resources relating to the user are grouped under the user folder.</p>
  
  <p>I'm stuck though for what to do with my routes file.</p>
  
  <p>When I rake routes, I can see:</p>
  
  <pre><code> users#index {:controllers=&gt;{:users=&gt;"users/users"}}
                                   POST     /users(.:format)                        users#create {:controllers=&gt;{:users=&gt;"users/users"}}
                          new_user GET      /users/new(.:format)                    users#new {:controllers=&gt;{:users=&gt;"users/users"}}
                         edit_user GET      /users/:id/edit(.:format)               users#edit {:controllers=&gt;{:users=&gt;"users/users"}}
                              user GET      /users/:id(.:format)                    users#show {:controllers=&gt;{:users=&gt;"users/users"}}
                                   PATCH    /users/:id(.:format)                    users#update {:controllers=&gt;{:users=&gt;"users/users"}}
                                   PUT      /users/:id(.:format)                    users#update {:controllers=&gt;{:users=&gt;"users/users"}}
                                   DELETE   /users/:id(.:format)                    users#destroy {:controllers=&gt;{:users=&gt;"users/users"}}
  </code></pre>
  
  <p>In my routes file, I've tried a few things (set out below) - none of them work:</p>
  
  <pre><code>Rails.application.routes.draw do
    devise_for :users,
               :controllers =&gt; {
                  :sessions =&gt; 'users/sessions',
                  :registrations =&gt; "users/registrations",
                  :omniauth_callbacks =&gt; 'users/omniauth_callbacks'
                }
  
    resources :identities, 
      :controllers =&gt; {
          :identities =&gt; 'users/identities'
      }
  
  
    resources :users do
    scope module: :users do
      resources :users
      end
      end 
  
    root 'home#index'
  
  end
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>resources :users,
      :controllers =&gt; {
          :users =&gt; 'users/users'
      }
  </code></pre>
  
  <p>Each time, I get an error that says:</p>
  
  <pre><code>ActionController::RoutingError at /users
  uninitialized constant UsersController
  </code></pre>
  
  <p>I don't know what I need to do to get this working. I have changed each of my controllers that is nested inside the controllers/users folder with a prefix of:</p>
  
  <pre><code> Users:: 
  </code></pre>
  
  <p>Can anyone see how to set this up so that I can keep my files neatly organised?</p>
  
  <p>Note: I haven't created the same file directory structure in my models folder. I want to - but I'm concerned that I'm not able to figure this out for the controllers. Can anyone see what I'm doing wrong?</p>