views:

30

answers:

2

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?

+1  A: 

Yes _confirmation is a convention that can be overridden Add

attr_accessor :password_confirmation

To your model.

Sam C
A: 

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

sarnold