Forum: Ruby on Rails Validate presence of 2 fields

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.
Lon B. (Guest)
on 2005-12-13 22:52
(Received via mailing list)
Is it possible top validate the presence of 2 field?

Maybe I am blind, but I can't figure out how to validate based on the
presence of 2 fields.

--
Lon B.
http://www.speedymac.com
AIM: spdemac
Kyle M. (Guest)
on 2005-12-13 23:04
(Received via mailing list)
Just do validates_presence_of on each?  I suspect that that's not what
you wanted to hear, and that I didn't understand your problem, so to
roll your own validation, you can use validates_each.  Example:

validates_each(:field1, :field2) do |record, field_name, field_value|
  #This block is run once for each field, so 2x in this example.
  record.errors.add "is invalid" if some_test.fails?
end
This topic is locked and can not be replied to.