Rails - checking parameters depends on other parameters

I have 2 fields which mobile_noand telephone_no. I want to check these fields with the following condition:

If mobile_no is present on submit, then
  don't validate telephone_no


if telephone_no is present on submit, then
  don't validate mobile_no

How can i do this?

+4
source share
1 answer

you can try this in your model:

validates :mobile_no, presence: true, unless: :telephone_no?
validates :telephone_no, presence: true, unless: :mobile_no?
+4
source

All Articles