I have a User model that can save two types of users:
So, when a normal user registers, the model should validate password fields with has_secure_password and validate the presence of the password field:
has_secure_password
validates :password, presence: true
This works. I have no problem with this.
But when a user wants to register through Facebook, the password is not needed, because provider and uid will be filled instead. The problem is that I don't know how to disable has_secure_password in this case. I have tried this:
has_secure_password
validates :password, presence: true, unless: :facebook_user?And this is the facebook_user method:
def facebook_user?
provider != nil && uid != nil
end
But it doesn't work, as it is still complaining about password_digest:
@messages={:password_digest=>["can't be blank"]}
What am I doing wrong? Isn't it possible to disable has_secure_password selectively?