Reputation: 8689
I have form which has 2 sets of fields like Field X and Confirm Field X. Only Field X is part of the model. How can I validate that both x and confirm_x are the same? Can I do this in rails or I have to use javascript?
Upvotes: 1
Views: 150
Reputation: 1752
You can use validates_confirmation_of in your model. From the API:
Model:
class Person < ActiveRecord::Base
validates_confirmation_of :user_name, :password
validates_confirmation_of :email_address,
:message => "should match confirmation"
end
View:
<%= password_field "person", "password" %>
<%= password_field "person", "password_confirmation" %>
Upvotes: 2