devise icon indicating copy to clipboard operation
devise copied to clipboard

Devise fails with Mongoid 3

Open clody69 opened this issue 14 years ago • 4 comments

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

clody69 avatar May 31 '12 20:05 clody69

Can you please provide a patch?

josevalim avatar Jun 01 '12 08:06 josevalim

Check this pull request https://github.com/plataformatec/devise/pull/1892

clody69 avatar Jun 03 '12 19:06 clody69

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 ?

lgs avatar Jul 23 '12 18:07 lgs

Please use the mailing list for questions.

josevalim avatar Jul 23 '12 18:07 josevalim