Rails validation that one value does not equal another

You can add a custom validation:

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

That will be called every time your object is validated (either explicitly or when you save with validation) and will add an error to both of the fields. You might want an error on both fields to render them differently in the form.

Otherwise you could just add a base error:

errors.add(:base, 'a must be different to b')

In your model:

validate :text_fields_are_not_equal

def text_fields_are_not_equal
  self.errors.add(:base, 'Text_field1 and text_field2 cannot be equal.') if self.text_field1 == self.text_field2
end