devise: instance the current_user using single table inheritance

devise, ruby-on-rails, ruby-on-rails-3, single-table-inheritance

Solution

it's exactly what you need : http://blog.jeffsaracco.com/ruby-on-rails-polymorphic-user-model-with-devise-authentication

you need to override the sign in path method in your application controller, hope it help.

Problem

I am using rails 3.0.9 and devise for authentication. Now I'm trying to use single table inheritance because I need to use polymorphism, so I have two classes: UserType1 and UserType2, which inherit from User class. I need that Devise instance correctly the current_user depending the type of user. For example, ``` class User < ActiveRecord::Base #devise and other user logic end class UserType1 < User def get_some_attribute return "Hello, my type is UserType1" end end class UserType2 < User def get_some_attribute return "Hello, my type is UserType2" end end In controller class MyController < ApplicationController def action @message = current_user.get_some_attribute #depending the type using polymorphism render :my_view end end ```

Original source