first rails program here. I would like to go a little further than req'd and, for instance, allow entries into an address book accept a first name OR a last name or both. In other words, I would like to validate_presence_of first OR last, and only throw an exception if both are missing, a super easy thing to do in C++, but what would syntax look like in Ruby?
Couldn't you just run a conditional validates presence of last_name if first_name is blank? If the first name is NOT blank, then the validation won't run, but if it is blank then it makes sure the last_name is not also blank...
validates :last_name, :presence => true, :if => "first_name.blank?"
You want a custom validation method as described here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With