Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 548
THpubs Avatar asked May 25 '14 15:05

THpubs


People also ask

Is devise gem secure?

If you're using Rails to build your application, you can use Devise, a gem which is designed to make authentication easy. Fortunately, Devise has been used in production applications for years. It's known to be secure.


1 Answers

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
like image 82
matanco Avatar answered Sep 23 '22 06:09

matanco