devise: not requiring email

2020-02-27 11:12发布

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?

4条回答
贪生不怕死
2楼-- · 2020-02-27 11:19

If the issue was that the service in-question wasn't providing an email to you, this is a bit cleaner of a solution:

https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview#user-didnt-allow-email-permissions

查看更多
我命由我不由天
3楼-- · 2020-02-27 11:24

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

查看更多
\"骚年 ilove
4楼-- · 2020-02-27 11:36

Some references say you shouldn't remove :validatable, because it would remove password validations.

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.

查看更多
何必那么认真
5楼-- · 2020-02-27 11:40

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

查看更多
登录 后发表回答