Forum: Ruby on Rails custom validation in model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
straightflush (Guest)
on 2005-11-26 20:31
(Received via mailing list)
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
vox (Guest)
on 2005-11-26 20:39
(Received via mailing list)
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
ksibilev (Guest)
on 2005-11-26 21:04
(Received via mailing list)
Check out validates_confirmation_of

Kent
This topic is locked and can not be replied to.