plataformatec/devise — Issue #1595: ORM not set correctly in config/initializers/devise.rb when using Mongoid and ActiveRecord
Author: mykoweb
Created: 2012-01-24 07:04:20+00:00
State: open

I am using both ActiveRecord and mongoid. My User model is using ActiveRecord but when mongoid is being used, "rake db:migrate" becomes confused and assumes User is a Mongoid document and results in the following error:

$> rake db:migrate
rake aborted!
undefined method `devise' for User(Table doesn't exist):Class

Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

A workaround when running "rake db:migrate" is to manually change the config/initializers/devise.rb file by changing:

require 'devise/orm/mongoid'

to:

require 'devise/orm/active_record'

However, I shouldn't have to manually do this. If I generate the User model using:

> rails g active_record:devise User

Then devise should automatically generate the config/initializers/devise.rb with the correct settings for the ORM.

I am using Ruby 1.9.2p290, Rails 3.1.0, Mongoid 2.3, bson_ext 1.4, and Devise 1.5.3.

Best,

Mike