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?

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.