title: How do I set a model instance as invalid after validations are run but before it's saved?
body: <p>I have a standard active record model with an attributes that is required:  </p>
  
  <pre><code>class Sample &lt; ActiveRecord::Base
    has_many :colors
  
    before_validation :grab_colors
  
    validates_presence_of :size
    validate :number_of_colors
  
    private
  
    def grab_colors
      # grab x number of colors | x = size
    end
  
    def number_of_colors
      self.errors.add("size","is to large.") if colors.count &lt; size
    end
  end
  </code></pre>
  
  <p>My problem is that the <em>grab_colors</em> method requires the <em>size</em> attribute but performs a result that needs to be validated as well. In the case above <em>size</em> is used before it's presence is validated.  </p>
  
  <p>Can I set the instance as invalid and stop the save process after all validation have been made?</p>