0

I have my user models validation for password confirmation like this

validate_confirmation_of :password

This add the error message doesn't match to the password field, but I need this error message on the password_confirmation field.

Can this be achieved in any other way.? I need this because, I use client side validations to show errors in form and I want this error to appear on the password_confirmation field rather than on the password field.

aBadAssCowboy
  • 2,440
  • 2
  • 23
  • 38

1 Answers1

1

You can write a simple custom validation:

class User
  validate :password_confirmation_matches_password

  def password_confirmation_matches_password
    if password != password_confirmation
      errors.add(:password_confirmation, "isn't the same")
    end
  end
end
Max Hollmann
  • 345
  • 2
  • 8