How do I validate that either one field or another is filled out in Ruby on Rails? -
i have contact information. user needs fill out @ least 1 of 3 fields, fields being email address, mailing address, or phone number.
how in ruby on rails?
while justin shows may fine, rails provide formal scheme doing type of thing. allows create custom validator of predefined validators.
see "validates_with" more details, here example rails guide:
class goodnessvalidator < activemodel::validator def validate(record) if record.first_name == "evil" record.errors[:base] << "this person evil" end end end class person < activerecord::base validates_with goodnessvalidator end
Comments
Post a Comment