TIL - Rails XOR validation 10 Jul 2024 | Coding rails ruby til I learned how to do XOR validationTalk is cheap, show me the codeclass SomeClass include ActiveModel::Validations validate :a_or_b? private def a_or_b? return if a.blank? ^ b.blank? errors.add( :base, :a_or_b_required, message: 'either a or b must be present, but not both' ) end endCopy Share this on: Mail - Twitter - Facebook TIL - Git log between dates