title: Rails ActiveRecord custom validator returns false but model.save is accepted without rollback
body: <p>i have a model which defines size ranges like 100m² to 200m². I wrote a validator:</p>
  
  <pre><code>class SizeRange &lt; ActiveRecord::Base
      validate :non_overlapping
  
      def non_overlapping
          lower_in_range = SizeRange.where(lower_bound: lower_bound..upper_bound)
          upper_in_range = SizeRange.where(upper_bound: lower_bound..upper_bound)
          if lower_in_range.present?
              errors.add(:lower_bound, 'blablabla')
          end
          if upper_in_range.present?
              errors.add(:upper_bound, 'blablabla')
          end
      end
  end
  </code></pre>
  
  <p>My guess was, that when I try to save a new model which lower or upper bound appears to be in the range of an other SizeRange instance the validator would mark the model as invalid and the save action would be aborted.
  What really happened is that my model got saved and assigned an id, but when I call model.valid? it returns false (So my validator seems to do what it should).</p>
  
  <p>Is there anything I could have done wrong, or did I not understand how the validators work? Can I force the validator to abort the save action?</p>
  
  <p>Another question:
  Is there any way to enforce a constraint like that through database constraints? I think I would prefer a solution on database side.</p>
  
  <p>Thanks for your help!</p>