plataformatec/devise — Issue #1395: Devise not finding reopened User class
Author: baphled
Created: 2011-10-19 18:12:24+00:00
State: open

I have an app that has centralised business logic that is stored in a single gem. I'm attempting to introduce this into the Rails app so that I can DRY things up.

Having said this devise seems to fall over once this gem is introduced.

The gem includes a basic User class with no dependency to Devise what so ever.

class Foo::User
include Mongoid::Document
include Mongoid::TimeStamps

field :username
field :email
end

The application on the other hand does, so I have reopened the class and add the following.

class Foo::User
include Mongoid::Document
include Mongoid::TimeStamps

devise :database_authenticatable, :registerable, :token_authenticatable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
end

After removing the private gem everything passes again.

I have done some digging and it seems the devise finds the Foo::User class first and runs respond_to? on this instead of the version in the models directory.

You can find the stacktrace here: https://gist.github.com/1299110