Devise fails with Mongoid 3
The default User model that is created with the devise generator fails to load with Mongoid 3.0.0.rc
Problem:
Invalid option :null provided for field :email.
Summary:
Mongoid requires that you only provide valid options on each field definition in order to prevent unexpected behaviour later on.
Resolution:
When defining the field :email on 'User', please provide valid options for the field. These are currently: as, default, identity, label, localize, metadata, pre_processed, subtype, type, versioned. If you meant to define a custom field option, please do so first like so:
The problem is that in mongoid you cannot use the parameter :null => false to specify that the field must not be blank. Instead of this:
## Database authenticatable
field :email, :type => String, :null=> false, :default => ""
field :encrypted_password, :type => String, :null=> false, :default => ""
it should be:
## Database authenticatable
field :email, :type => String, :default => ""
field :encrypted_password, :type => String, :default => ""
validates_presence_of :email
validates_presence_of :password
Can you please provide a patch?
Check this pull request https://github.com/plataformatec/devise/pull/1892
This doesn't work if you have two validation systems in place. In my case devise is for rails_admin ( admins authentication ), while my users are logging with omniauth/omniauth-github and that cause an error due to the omniauth-github doesn't have password :
Mongoid::Errors::Validations in SessionsController#create Problem: Validation of User failed. Summary: The following errors were found: Password can't be blank Resolution: Try persisting the document with valid data or remove the validations.
any idea on how to work around that ?
Please use the mailing list for questions.