I have a User model that can save two types of users:
1. Password-protected users (for this I need has_secure_password)
2. Facebook users (for this I don't need has_secure_password, but two
different fields: provider and uid)
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?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/HQLLN0k74pcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.