设计:不需要电子邮件 [英] devise: not requiring email
问题描述
我不希望使用devise登录时需要电子邮件。我从config / initializers / devise.rb中删除了电子邮件:
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?
推荐答案
好像您在数据库中将电子邮件字段设置为 not NULL或 Allow Null设置为false。
您直接从数据库中得到一个错误。
假设您的用户模型被称为用户,则需要添加休闲迁移来解决以下问题:
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
文档:
http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/change_column
这篇关于设计:不需要电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!