在Rails中使用Devise宝石如何创建一个没有电子邮件和密码的用户? [英] In Rails when using the Devise gem how to create a user without email and password?

查看:107
本文介绍了在Rails中使用Devise宝石如何创建一个没有电子邮件和密码的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Rails应用中,管理员是将用户添加到系统的人员。如果用户没有电子邮件,则不会为他生成密码,他无法登录,但如果用户有电子邮件,则会生成密码。但问题是,设计不会允许空白的密码。我们如何解决这个问题?

In my Rails app, Admins are the people who add users to the system. If the user doesn't have an email, a password won't be generated for him and he can't log in. But if the user have an email, a password will be generated. But the problem is, devise won't allow blank passwords. How can we fix this?

推荐答案

您可以在用户模型中覆盖它们:

you can override them in your user model:

def password_required?
  false
end

def email_required?
  true
end

编辑:

def password_required?
   new_record? ? false : super
end

这篇关于在Rails中使用Devise宝石如何创建一个没有电子邮件和密码的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆