Dave Silvester
2006-Mar-14 12:14 UTC
[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 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 Silvester Rent-A-Monkey Website Development http://www.rentamonkey.com/ PGP Key: http://www.rentamonkey.com/pgpkey.asc
Hi Dave, There was a posting on 1/20/06 by Adam Denenberg reporting a similar problem with password confirmation. He didn''t get any replies. Best regards, Bill ----- Original Message ----- From: "Dave Silvester" <dave@rentamonkey.com> To: "Ruby On Rails" <rails@lists.rubyonrails.org> 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 upagainst> here is more of a bug or an anomaly that I''m unaware of (or that haschanged> in a recent version). > > I had a fully working validates_confirmation_of :email_address field in myapp> - was one of the first things I set up, extremely simple, been working fora> long time. > > Then one day I notice that it''s not working any more - the validatorbasically> 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 checkedthe> 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 theform,> yet the confirmation check still doesn''t seem to take place. > > It was my belief (and this certainly worked fine exactly like this for along> 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 andmatch> 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.0and> Ruby 1.8.4. > > This thread appears to be discussing a similar problem, but it''s not quitethe> same: http://thread.gmane.org/gmane.comp.lang.ruby.rails/25445 > > I''ve also searched the Rails Trac bugs database, and can''t find anythingabout> 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 along> 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, butthis> used to work fine, and it''s just stopped working. > > Anyone else? Thanks for your help! > > Cheers, > > ~Dave > > -- > > Dave Silvester > Rent-A-Monkey Website Development > http://www.rentamonkey.com/ > > PGP Key: http://www.rentamonkey.com/pgpkey.asc > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Dave Silvester
2006-Mar-17 02:59 UTC
[Rails] validates_confirmation_of has stopped working
On Tuesday 14 Mar 2006 12:56, Bill Walton wrote:> There was a posting on 1/20/06 by Adam Denenberg 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 ... 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 Silvester Rent-A-Monkey Website Development http://www.rentamonkey.com/ PGP Key: http://www.rentamonkey.com/pgpkey.asc
Dave Silvester
2006-Apr-03 02:50 UTC
[Rails] validates_confirmation_of has stopped working
On Tuesday 14 Mar 2006 12:14, Dave Silvester 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 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 Silvester Rent-A-Monkey Website Development http://www.rentamonkey.com/ PGP Key: http://www.rentamonkey.com/pgpkey.asc
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?