Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

devise: not requiring email

I would like to NOT require email for signing in using devise. I removed email from config/initializers/devise.rb:

config.authentication_keys = [ :login ]

and added this to my user model:

def email_required?
  false
end

However, I am getting this error when I try to save the user:

SQLite3::SQLException: users.email may not be NULL

Am I suppose to change something in the migration?

like image 917
stackOverlord Avatar asked Feb 06 '12 19:02

stackOverlord


3 Answers

In my case, I removed the column email from my users in the database, and Devise started to crash. I added this:

# app/models/user.rb
def email_required?
  false
end

def email_changed?
  false
end

and it worked properly.

Please note that removing :validatable would remove password validations. So some references say you shoudn't remove it.


Tip: Add a simple comment above those lines explaining your motives. Those after you will be thankful

like image 132
Mauricio Moraes Avatar answered Oct 19 '22 21:10

Mauricio Moraes


It looks like you have the email field set in the database as "not NULL" or "Allow Null" to false. And you are getting an error directly from the database. Assuming that your user model is called user you need to add the fallowing migration to fix that:

change_column :users, :email, :string, :null => true 

Documentation: http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/change_column

like image 40
VelLes Avatar answered Oct 19 '22 20:10

VelLes


Additional to removing "required" from :email column you need to remove ":validatable" from user model.

like image 23
Vitaly Bezkrovny Avatar answered Oct 19 '22 22:10

Vitaly Bezkrovny