Hello,
I have problem with custom validator which should check such
situation:
I have two fields text_field 'object', 'others' and text_field
'object', 'others_area'
I "raise" error if others is nil but others_area is filled up also
when others is not nil but others_area isn't numeric
If both fields are nil it's ok i allow such situation.
How can I do that in one correlated validator?
Hi thx for response, i tried to write way you described but stuck with
such code:
def validates_correlated_presence_of(*attr_names)
send(validation_method(:create)) do |record|
value1 = record.send(attr_names[0])
value2 = record.send(attr_names[1])
if(!value1.nil? || !value2.nil?)
#validates_presence_of(attr_names[0], attr_names[1], :message =>
"must be filled")
validates_presence_of(attr_names[0], :message => "must be
filled")
validates_presence_of(attr_names[1], :message => "must be
filled")
end
end
end
Validator goes all lines of code but
validates_presence_of(attr_names[0], :message => "must be filled")
isn't adding any errors to record object. Is it possible to embed one
validator into another?