title: Including a Module in a Controller when using a different folder structure for the Model?
body: <p>I'm trying to create a controller in:</p>
  
  <pre><code>app/controllers/admin/account/users_controller.rb
  </code></pre>
  
  <p>And my model in:</p>
  
  <pre><code>app/models/account/user.rb
  </code></pre>
  
  <p>The desired table name is "account_users".</p>
  
  <p>If I run:</p>
  
  <pre><code>rails g scaffold account/user username:string
  </code></pre>
  
  <p>Then the scaffold generates the files correctly, and everything works.  I now put my controller and view user files into an admin folder (I'm omitting the view, since the problem is related to the controller and model):</p>
  
  <pre><code>scaffold generated: app/controllers/account/users_controller.rb 
  relocated: app/controllers/admin/account/users_controller.rb
  </code></pre>
  
  <p>In the controller I have to modify the following:</p>
  
  <pre><code>scaffold generated:  class Account::UsersController &lt; ApplicationController
  modified:  class Admin::Account::UsersController &lt; ApplicationController
  </code></pre>
  
  <p>I changed my routes to:</p>
  
  <pre><code>namespace :admin do
    namespace :account do
      resources :users
    end
  end
  </code></pre>
  
  <p>So far so good, everything works when I go to localhost:3000/admin/account/users</p>
  
  <p>I'm trying to DRY up my controller now, every database call is prefixed with the "Account::" module. It looks something like this:</p>
  
  <pre><code>class Admin::Account::UsersController &lt; ApplicationController
    def index
      @account_users = Account::User.all
    end
  </code></pre>
  
  <p>When I change the controller to:</p>
  
  <pre><code>class Admin::Account::UsersController &lt; ApplicationController
  
    include Account
  
    def index
      @account_users = User.all
    end
  </code></pre>
  
  <p>I get an error saying that the "User" is an uninitialized constant.  My first thought is that the Account Module is not being found.  My Account Module looks like this (app/models/account.rb):</p>
  
  <pre><code>module Account
    def self.table_name_prefix
      'account_'
    end
  end
  </code></pre>
  
  <p>I wrote some debug code inside this Module, and it is executing, so it does look like the Account module is being included in the controller.</p>
  
  <p>I'm thinking that the controller is not recognizing the "account_" prefix, and thinks that when I call User.all, it literally is looking for a users table instead of an account_users table.  </p>
  
  <p>So my question is, does anyone know if you can include a module in a controller when using a different folder structure for the model and controller?</p>
  
  <p>I'm using Rails 4.0 and Ruby 2.0.0.  Thanks if anyone can help!</p>