You can add a custom check:
class Something validate :fields_a_and_b_are_different def fields_a_and_b_are_different if self.a == self.b errors.add(:a, 'must be different to b') errors.add(:b, 'must be different to a') end end
This will be called every time your object is checked (either explicitly, or when you save it with a check), and adds an error to both fields. You may need an error in both fields to make them different in form.
Otherwise, you can simply add a basic error:
errors.add(:base, 'a must be different to b')
source share