title: Rails 4 - Using namespaced STI models with devise
body: <p>My rails app has 5 user models that extend <code>User</code>. All of which have the namespace <code>User::UserTypeHere</code>. When I attempt to logout of my application, devise tries to access the models as if they belong to the top level namespace, and I get the following error:</p>
  
  <pre><code>"The single-table inheritance mechanism failed to locate the subclass: 'SuperUser'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance..."
  </code></pre>
  
  <p>How do I set up my routes in a way that devise will recognize my namespaced models?</p>
  
  <p><strong>routes.rb snippet</strong></p>
  
  <pre><code>...
  devise_for :users, skip: [:sessions, :passwords, :confirmations, :registrations, :unlocks]
  devise_scope :user do
  
  # authentication
  unauthenticated :user do
    root to: 'users/devise/sessions#new', as: 'new_user_session'
  end
  authenticated :user do
    root to: 'application#index'
  end
  
  get '/login', to: 'users/devise/sessions#new', as: 'user_login_view'
  post '/login', to: 'users/devise/sessions#create', as: 'user_session'
  get '/logout', to: 'users/devise/sessions#destroy', as: 'destroy_user_session'
  
  # registrations
  get '/join', to: 'users/registrations#new', as: 'new_user_registration'
  post '/join', to: 'users/registrations#create', as: 'user_registration'
  
  # user accounts
  scope '/account' do
    # confirmation
    get '/verification', to: 'users/confirmations#verification_sent', as: 'user_verification_sent'
    get '/confirm', to: 'users/confirmations#show', as: 'user_confirmation'
    get '/confirm/resend', to: 'users/confirmations#new', as: 'new_user_confirmation'
    post '/confirm', to: 'users/confirmations#create'
  
    # passwords
    get '/reset-password', to: 'users/passwords#new', as: 'new_user_password'
    get '/reset-password/change', to: 'users/passwords#edit', as: 'edit_user_password'
    put  '/reset-password', to: 'users/passwords#update', as: 'user_password'
    post '/reset-password', to: 'users/passwords#create'
  
    # unlocks
    post '/unlock', to: 'users/unlocks#create', as: 'user_unlock'
    get '/unlock/new', to: 'users/unlocks#new', as: 'new_user_unlock'
    get '/unlock', to: 'users/unlocks#show'
  
    # settings &amp; cancellation
    # get '/cancel', to: 'users/registrations#cancel', as: 'cancel_user_registration'
    # get '/settings', to: 'users/registrations#edit', as: 'edit_user_registration'
    # put '/settings', to: 'users/registrations#update'
    # account deletion
    # delete '', to: 'users/registrations#destroy'
  end
  end
  ...
  </code></pre>
  
  <p><strong>user.rb (model)</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      devise :database_authenticatable, :registerable,
          :recoverable, :rememberable, :trackable, :validatable
  end
  </code></pre>
  
  <p><strong>users/super_user.rb (model)</strong></p>
  
  <pre><code>class Users::SuperUser &lt; User
      ...
  end
  </code></pre>
  
  <p><strong>users/devise/sessions_controller.rb</strong></p>
  
  <pre><code>class Users::Devise::SessionsController &lt; Devise::SessionsController
      ...
  end
  </code></pre>