How to add errors before updating attributes?
<p>I'm trying to handle the situation where the user has entered info incorrectly, so I have a path that follows roughly:</p>

<pre><code>class Thing &lt; AR
  before_validation :byebug_hook
  def byebug_hook
    byebug
  end
end

thing = Thing.find x
thing.errors.add(:foo, "bad foo")
# Check byebug here, and errors added
if thing.update_attributes(params)
  DelayedJobThatDoesntLikeFoo.perform
else
  flash.now.errors = #...
end

byebug for byebug_hook&gt; errors.messages #=&gt; {}
</code></pre>

<p>Originally I thought that maybe the model was running its own validations and overwriting the ones I added, but as you can see even when I add the before hook the errors are missing, and I'm not sure what's causing it</p>

<p>ACTUAL SOLUTION
So, @SteveTurczyn was right that the errors needed to happen in a certain place, in this case a service object called in my controller</p>

<p>The change I made was</p>

<pre><code>class Thing &lt; AR
validate :includes_builder_added_errors
    def builder_added_errors
      @builder_added_errors ||= Hash.new { |hash, key| hash[key] = [] }
    end

  def includes_builder_added_errors
    builder_added_errors.each {|k, v| errors.set(k, v) }
  end
end

and in the builder object
thing = Thing.find x
# to my thinking this mirrors the `errors.add` syntax better
thing.builder_added_errors[:foo].push("bad foo") if unshown_code_does_stuff?
if thing.update_attributes(params)
  DelayedJobThatDoesntLikeFoo.perform
else
  flash.now.errors = #...
end
</code></pre>