I have a User model with an email attribute. I’m using the following
validations:
validates_confirmation_of :email
validates_format_of :email,
:with => RFC822::EmailAddress,
:message => “must be a valid address in the form [email protected]”
validates_uniqueness_of :email, :message => “address has already
been taken. If you’ve forgotten your password, please click <a
href=“forgot_password”>here to reset it.”
validates_presence_of :email, :message => “address cannot be blank.”
This all works fine when a user is entering their information into the
signup form for the first time, however, the problem is when I’m
displaying an edit form to allow the user to change their details.
My client has asked that the user edit details form show the following
fields:
New Email: _____________
Confirm Email: _____________
so rather than show the current email address, the client wants both
of these boxes to be blank.
The problem is that if the user doesn’t enter a new email address, the
validations will fire, the object will be marked as invalid (since the
email address is blank) and any of the other options that may have
been changed will not be saved. So I need to figure out how to avoid
running the email validations if the user hasn’t entered a value for
new email. If anyone has any suggestions, please let me know.
Thanks,
Mike