I have four fields a, b, c, and d. All of them must be populated if any of them have a value.
So what I want to do is validate that they are all populated, if any of them have a value. I'm trying to determine the best way to do this. I think I could do this:
class User < ActiveRecord::Base
validates_presence_of :a, :b, :c, :if => lambda { self.d.present? }
validates_presence_of :b, :c, :d, :if => lambda { self.a.present? }
validates_presence_of :a, :c, :d, :if => lambda { self.b.present? }
validates_presence_of :a, :b, :d, :if => lambda { self.c.present? }
end
a
,b
,c
andd
in your actual code? What is the meaning behind those fields? \$\endgroup\$