简体   繁体   中英

In Rails when using the Devise gem how to create a user without email and password?

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

Edit:

def password_required?
   new_record? ? false : super
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM