I am unsure how to use a confirmation only field in my forms. The perfect example is when registering a user, you want them to type their password twice but you only want to have one record for it. The form fields; user[password] user[password_confirmation] form posted; user = User.new @params[:user] Error is thrown because there is no method for password_confirmation. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You just need to add: attr_accessor :password_confirmation to your user model. c. Chad wrote:> > I am unsure how to use a confirmation only field in my forms. The > perfect example is when registering a user, you want them to type their > password twice but you only want to have one record for it. > > The form fields; > user[password] > user[password_confirmation] > > form posted; > user = User.new @params[:user] > > Error is thrown because there is no method for password_confirmation.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
bobbylohan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Nov-06 03:44 UTC
Re: Confirmation fields on forms
deee --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Cayce Balara wrote:> You just need to add: > > attr_accessor :password_confirmation > > to your user model. > > c. > >Thanks! that works well... kind of.. It works on my User model above just as expected. On another model, it doesn''t work as expected... The form fields; bank[bank_account] bank[routing_number] bank[bank_account_confirmation] bank[routing_number_confirmation] In the model; attr_accessor :bank_account_confirmation attr_accessor :routing_number_confirmation validates_confirmation_of :bank_account validates_confirmation_of :routing_number Testing with values that should pass validation, it fails. Here is the failure debugged; --- &id001 !ruby/object:Bank attributes: routing_number: "1" account_id: 3 bank_account: "2" bank_account_confirmation: "2" errors: !ruby/object:ActiveRecord::Errors base: *id001 errors: routing_number: - doesn''t match confirmation bank_account: - doesn''t match confirmation new_record: true routing_number_confirmation: "1" Another oddity is that in the Bank model the errors will not show up by printing error_messages_for :bank If I fail the User model, error_messages_for :user will print the expected messages. Any clues? Thanks to all. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chad wrote:> > I am unsure how to use a confirmation only field in my forms. The > perfect example is when registering a user, you want them to type their > password twice but you only want to have one record for it. > > The form fields; > user[password] > user[password_confirmation] > > form posted; > user = User.new @params[:user] > > Error is thrown because there is no method for password_confirmation.If you add a validates_confirmation_of to your model, an acessor for the confirmation is created for you. No attr_accessor needed. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---