Confirm the presence of one field or another (OR)

So, I am looking at the link, but I am wondering how to do "OR" instead of "XOR". Does anyone know how to do this? I am trying to do this with Rails 3.

+5
source share
2 answers

I get it. all you need to change is ^ to &&

private def time_or_money if time.blank? && money.blank? errors[:base] << "Specify Time, Money or Both." end end 
+4
source

There is a short option for Rails 4 (not sure about Rails 3):

 validates :email, presence: { if: -> { username.blank? } } validates :username, presence: { if: -> { email.blank? } } 
+5
source

Source: https://habr.com/ru/post/1205111/


All Articles