Custom validation in model


#1

Hello,

is there a way to add a custom validation inside the model ?

like

validates_passwords_are_equal :password, :password_confirm

that would make sure the password and password_confirm fields are the
same ?

thanks
adam


#2

There’s a validation in the core that does precisely that:
validates_confirmation_of:
http://api.rubyonrails.com/classes/ActiveRecord/Validations/
ClassMethods.html#M000653

for custom validations use validates_each:
http://api.rubyonrails.com/classes/ActiveRecord/Validations/
ClassMethods.html#M000652

hth,
Stephen


#3

Check out validates_confirmation_of

Kent