简体   繁体   中英

Rails' validates_confirmation_of

I am trying to create a registration form (just for practice) and saw this method for rails and want to use it. However, I am quite confused on how I should use this. I have fields where each corresponds to an attribute in the database. Like I have text_field_tag(:username) and my model has t.string :username. For password confirmation, I have the password attribute in the model, but I do not have the confirmation attribute. I am wondering how I should go about doing this so that Rails will check for the right field. What should I name the confirmation field? is it just password_confirmation? Does this happen by convention? Can someone elaborate more about this function?

Yes _confirmation is a convention that can be overridden Add

attr_accessor :password_confirmation

To your model.

The 'confirmation' field is not stored in the database.

The field name is just password_confirmation : http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001395

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM