I'm using has_secure_password in my user model. On sign up I'm giving password and password confirmation fields .
I manually added validation to check if the password and confirmation match in my user model.
has_secure_password
validates :password, presence:true, length: {minimum:6}
validate :pass_valid
def pass_valid
errors.add(:base,"password and confirmation do not match") if password!=password_confirmation
end
my form looks like this
= f.label :'Password'
= f.password_field :password
= f.label :'Password Confirmation'
= f.password_field :password_confirmation
The form is giving error even when I enter a password confirmation that is different from password. I take that has_secure_password verifies that password and confirmation both match and I removed pass_valid method. Now user is created even though the password and confirmation do not match.
Can someone help me out?
P.S : I'm using protected-attributes in my gemfile. So added password and password_confirmation to attr_accessible in user model.