title: Ruby NoMethodError: undefined method `messages' for []:Array
body: <p>Since google did not help me in my quest to figure this out, I figured I would share it for anyone else that runs into this problem:</p>
  
  <p>When attempting to save a model, I get </p>
  
  <pre><code>NoMethodError: undefined method `messages' for []:Array
  0: /.../active_record/autosave_association.rb:491:in `_ensure_no_duplicate_errors'
  1: /.../active_support/callbacks.rb:413:in `block in make_lambda'
  2: /.../active_support/callbacks.rb:246:in `block in halting'
  3: /.../active_support/callbacks.rb:511:in `block in invoke_after'
  4: /.../active_support/callbacks.rb:511:in `each'
  5: /.../active_support/callbacks.rb:511:in `invoke_after'
  6: /.../active_support/callbacks.rb:132:in `run_callbacks'
  7: /.../active_support/callbacks.rb:825:in `_run_validation_callbacks'
  8: /.../active_model/validations/callbacks.rb:110:in `run_validations!'
  9: /.../active_model/validations.rb:335:in `valid?'
  </code></pre>
  
  <p>Example model:</p>
  
  <pre><code>class Foo &lt; ActiveRecord::Base
  
    def do_stuff
      @errors = []
      @errors &lt;&lt; 'Bad stuff' if self.bar &gt; 4
      @errors
    end
  
  end
  </code></pre>
  
  <p>Example code:</p>
  
  <pre><code>foo = Foo.first
  foo.do_stuff
  foo.save # or foo.valid?, etc.
  </code></pre>