# Validates\_confirmation\_of has stopped working

**URL:** <https://www.ruby-forum.com/t/validates-confirmation-of-has-stopped-working/54799>\
**Category:** Rails\
**Created:** [March 14, 2006, 1:15pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-has-stopped-working/54799 "2006-03-14T13:15:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [March 14, 2006, 1:15pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-has-stopped-working/54799/1 "2006-03-14T13:15:44Z")

</div>

Hi Railers,

I’m past considering myself a noob in Rails land - I think what I’m up  
against  
here is more of a bug or an anomaly that I’m unaware of (or that has  
changed  
in a recent version).

I had a fully working validates\_confirmation\_of :email\_address field in  
my app

- was one of the first things I set up, extremely simple, been working  
for a  
long time.

Then one day I notice that it’s not working any more - the validator  
basically  
doesn’t care if you fill in the email\_address field but not  
email\_address\_confirmation, and it certainly doesn’t care if they don’t  
match.

I’ve tried looking at the examples again, and my code follows them to  
the  
letter (with the exception that my field name is different). I’ve  
checked the  
logs and the appropriate parameters are being sent through.

In desperation, I even tried validates\_presence\_of  
:email\_address\_confirmation  
to ensure that it’s filled in - that works to enforce the field in the  
form,  
yet the confirmation check still doesn’t seem to take place.

It was my belief (and this certainly worked fine exactly like this for a  
long  
time) that if I had…

validates\_presence\_of :email\_address  
validates\_confirmation\_of :email\_address

… that would take care of enforcing that both fields are filled in and  
match  
each other.

I haven’t changed anything on this code, yet it’s stopped doing the  
confirmation validation.

Could anyone else confirm this is/isn’t the case? I’m running Rails  
1.0.0 and  
Ruby 1.8.4.

This thread appears to be discussing a similar problem, but it’s not  
quite the  
same: [http://thread.gmane.org/gmane.comp.lang.ruby.rails/25445](http://thread.gmane.org/gmane.comp.lang.ruby.rails/25445)

I’ve also searched the Rails Trac bugs database, and can’t find anything  
about  
this problem.

I’m enforcing the format of the email address using…

validates\_format\_of :email\_address,  
:with =\> /^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/,  
:message =\> “is not valid”,  
:if =\> Proc.new {|model| !model.email\_address.blank?}

…which combined with my other validations surely should (and did for a  
long  
time) take care of all possible scenarios with the email addresses.  
Meaning:

- Neither field present.
- Email address present, confirmation not.
- Confirmation present, email address not.
- Both present, don’t match.
- Both present, match, but format is not an email address.
- Both present, match, format is an email address.

So something is seriously amiss here, and I don’t know what it is, but  
this  
used to work fine, and it’s just stopped working.

Anyone else? Thanks for your help!

Cheers,

~Dave

–

Dave S.  
Rent-A-Monkey Website Development

> **[Tree Removal Service For Home & Businesses in Salt Lake City, UT](https://www.rentamonkey.com/)**
>
> Rent A Monkey Tree Service provides the safest, highest-quality tree removal for Salt Lake City, UT homes and businesses. Request a service today!

PGP Key: [http://www.rentamonkey.com/pgpkey.asc](http://www.rentamonkey.com/pgpkey.asc)

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [March 14, 2006, 2:11pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-has-stopped-working/54799/2 "2006-03-14T14:11:18Z")

</div>

Hi Dave,

There was a posting on 1/20/06 by Adam D. reporting a similar  
problem  
with password confirmation. He didn’t get any replies.

Best regards,  
Bill

----- Original Message -----  
From: “Dave S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: “Ruby On Rails” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: 2006-03-14 6:14 AM  
Subject: [Rails] validates\_confirmation\_of has stopped working

> Hi Railers,
> 
> I’m past considering myself a noob in Rails land - I think what I’m up  
> against  
> here is more of a bug or an anomaly that I’m unaware of (or that has  
> changed  
> in a recent version).
> 
> I had a fully working validates\_confirmation\_of :email\_address field in my  
> app
> 
> - was one of the first things I set up, extremely simple, been working for  
> a  
> long time.
> 
> Then one day I notice that it’s not working any more - the validator  
> basically  
> doesn’t care if you fill in the email\_address field but not  
> email\_address\_confirmation, and it certainly doesn’t care if they don’t  
> match.
> 
> I’ve tried looking at the examples again, and my code follows them to the  
> letter (with the exception that my field name is different). I’ve checked  
> the  
> logs and the appropriate parameters are being sent through.
> 
> In desperation, I even tried validates\_presence\_of  
> :email\_address\_confirmation  
> to ensure that it’s filled in - that works to enforce the field in the  
> form,  
> yet the confirmation check still doesn’t seem to take place.
> 
> It was my belief (and this certainly worked fine exactly like this for a  
> long  
> time) that if I had…
> 
> validates\_presence\_of :email\_address  
> validates\_confirmation\_of :email\_address
> 
> … that would take care of enforcing that both fields are filled in and  
> match  
> each other.
> 
> I haven’t changed anything on this code, yet it’s stopped doing the  
> confirmation validation.
> 
> Could anyone else confirm this is/isn’t the case? I’m running Rails 1.0.0  
> and  
> Ruby 1.8.4.
> 
> This thread appears to be discussing a similar problem, but it’s not quite  
> the  
> same: [http://thread.gmane.org/gmane.comp.lang.ruby.rails/25445](http://thread.gmane.org/gmane.comp.lang.ruby.rails/25445)
> 
> I’ve also searched the Rails Trac bugs database, and can’t find anything  
> about  
> this problem.
> 
> I’m enforcing the format of the email address using…
> 
> validates\_format\_of :email\_address,  
> :with =\> /^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/,  
> :message =\> “is not valid”,  
> :if =\> Proc.new {|model| !model.email\_address.blank?}
> 
> …which combined with my other validations surely should (and did for a  
> long  
> time) take care of all possible scenarios with the email addresses.  
> Meaning:
> 
> - Neither field present.
> - Email address present, confirmation not.
> - Confirmation present, email address not.
> - Both present, don’t match.
> - Both present, match, but format is not an email address.
> - Both present, match, format is an email address.
> 
> So something is seriously amiss here, and I don’t know what it is, but  
> this

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [March 17, 2006, 3:59am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-has-stopped-working/54799/3 "2006-03-17T03:59:29Z")

</div>

On Tuesday 14 Mar 2006 12:56, Bill W. wrote:

> There was a posting on 1/20/06 by Adam D. reporting a similar  
> problem with password confirmation. He didn’t get any replies.

Cheers Bill - on list as well as off list! I’ve emailed Adam but no  
reply  
yet. I’m wondering if it’s this bug…

[http://dev.rubyonrails.org/ticket/785](http://dev.rubyonrails.org/ticket/785)

… though the description isn’t completely clear so I can’t be sure.

The thing I can’t understand is that this WAS working perfectly, and  
that as  
far as I know I haven’t changed anything with it except keeping my Rails  
version up to date with the current gem version.

Anyone got any good alternative suggestions for a way to homebrew a  
confirmation field using custom validators? I’m guessing it shouldn’t  
be too  
hard to do, but I only want to do that as a last resort, since really  
I’d  
rather it happened using the official built-in way of doing it if  
possible.

It’s just, I really need this feature to work properly again - and soon!  
:-S

~Dave

–

Dave S.  
Rent-A-Monkey Website Development

> **[Tree Removal Service For Home & Businesses in Salt Lake City, UT](https://www.rentamonkey.com/)**
>
> Rent A Monkey Tree Service provides the safest, highest-quality tree removal for Salt Lake City, UT homes and businesses. Request a service today!

PGP Key: [http://www.rentamonkey.com/pgpkey.asc](http://www.rentamonkey.com/pgpkey.asc)

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [April 17, 2006, 12:50am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-has-stopped-working/54799/4 "2006-04-17T00:50:23Z")

</div>

I have also recently (well its the first time I have wanted to use  
validates\_confirmation\_of) been having problems with this particular  
validation method.

Looking at the script/console I would say that the model just isnt  
accepting the _confirmation attribute at all. Are we required to add an  
attr\_accessor or other attr_ notification to the model in order to use  
this validation mechanism?

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [April 3, 2006, 4:52am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-has-stopped-working/54799/5 "2006-04-03T04:52:53Z")

</div>

On Tuesday 14 Mar 2006 12:14, Dave S. wrote:

> I had a fully working validates\_confirmation\_of :email\_address field in my  
> app - was one of the first things I set up, extremely simple, been working  
> for a long time.
> 
> Then one day I notice that it’s not working any more - the validator  
> basically doesn’t care if you fill in the email\_address field but not  
> email\_address\_confirmation, and it certainly doesn’t care if they don’t  
> match.

Sorry to resurrect an extinct thread and reply to myself, but following  
on  
from my original message that you can read in full at:

[http://www.ruby-forum.com/topic/57951#47432](http://www.ruby-forum.com/topic/57951#47432)

I’ve finally figured out what wasn’t working, and why my  
validates\_confirmation\_of had stopped caring.

In my app, it’s a multi-stage form, where I’m saving things to the  
session,  
but also re-loading stuff from previous values in order to preserve  
fields  
even where the record isn’t saved. Basically, a system that allows you  
to  
jump about between different stages of the process and remembers things  
whatever you do, validating at each stage but only saving to the  
database  
right at the end.

Anyway… so what I was doing was storing the values in my session,  
recalling  
and combining them with new values when the form was submitted to build  
up  
the full amount of info required.

When saving the object to the session, all the true fields (those of the  
database table) get saved fine, but the confirmation virtual field is  
not  
saved, so at the point I recall previous data and create a new combined  
object, that foo\_confirmation field is actually reset to nil.

I’m still not 100% sure of the exact way or position it’s breaking it,  
but the  
remedy has been to copy in the foo\_confirmation field from the params if  
it’s  
set. Rather like this:

if params[:blah][:foo\_confirmation]  
@blah.foo\_confirmation = params[:blah][:foo\_confirmation]  
end

Now my validators work properly. Thought I’d just post a follow-up, in  
case  
anybody else ever finds themselves in this arrgh-hair-tearing-out  
scenario.

I don’t think it’s a bug as such, probably just a side-effect of  
storing,  
recalling and combining values using the session like this. (Since my  
system  
preserves all input - even invalid or incomplete input.)

In hindsight, there may have been a more efficient way to do what I’ve  
had to  
do, but as this was my first non-trivial Rails project (and although  
I’ve got  
quite a few Rails sites done now, this one is still ongoing because it’s  
very  
non-trivial!) I’ve picked up a lot more tricks since back when I was  
planning  
this.

Anyway, here’s hoping that my follow-up helps someone else in the same  
situation at some point.

Cheers,

~Dave

–

Dave S.  
Rent-A-Monkey Website Development

> **[Tree Removal Service For Home & Businesses in Salt Lake City, UT](https://www.rentamonkey.com/)**
>
> Rent A Monkey Tree Service provides the safest, highest-quality tree removal for Salt Lake City, UT homes and businesses. Request a service today!

PGP Key: [http://www.rentamonkey.com/pgpkey.asc](http://www.rentamonkey.com/pgpkey.asc)
