views:

79

answers:

1

I know that the RoR can do the validation in the models. But I want to confirm the user's password in the views. I means, it show two textfield for user to type password twice to ensure the user type the password correct, but in the database I only store one value. How can I handle it in the RoR?

+6  A: 

In your model do:

validates_confirmation_of :password

In your view do:

<%= form.password_field :password %>
<%= form.password_field :password_confirmation %>

This is using the built in rails confirmation validation. It's will add the virtual accessor for you.

jonnii
Wow, that's so sample to do so. Er.... ...One more thing, how can I check all the validation in RoR, is there any document out there? Thx in advance. Xmas.
Ted Wong
You can check api docs online here http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html
nas