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

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -