title: How do I serialize ActiveModel errors for later translation?
body: <p>I have a situation wherein a user submits some data to a web server (Rails) that will be processed in the background:</p>
  
  <pre><code>POST /fibonacci/6012 HTTP/1.1
  Host: example.com
  </code></pre>
  
  <p>The server responds with a link to the background job that the user can use to check the status:</p>
  
  <pre><code>HTTP/1.1 202 Accepted
  Location: http://example.com/jobs/5699121
  </code></pre>
  
  <p>The important thing to note is that <em>any</em> (authorized) user can check the status of the job. This means that I have to communicate any error messages from the worker back to the web server <em>symbolically</em>. I can't figure out a way to do so for ActiveModel errors. For example:</p>
  
  <pre><code>class FibonacciCalculation
    include ActiveModel::Validations
  
    attr_reader :input
    validates_presence_of :input
    validates_inclusion_of :input, :in =&gt; 0..10_000,
                                   :allow_blank =&gt; true
  
    def initialize(params = {})
      @input = params[:input]
    end
  
    def output
      # do fibonacci calculation
    end
  end
  </code></pre>
  
  <p>If I create such an object with <code>FibonacciCalculation.new(:input =&gt; -5)</code> and then get out the errors, I get an <code>ActiveModel::Errors</code> object, but I can't figure out how to serialize that. Asking for <code>errors[:input]</code> gives me <code>["can't be blank"]</code> or <code>["is not included in the list"]</code>, which are already translated. Similarly, <code>errors.as_json</code> returns something like</p>
  
  <pre><code>`{ "errors" =&gt; [ "can't be blank" ] }`
  </code></pre>
  
  <p>How can I get something like <code>{ :input =&gt; [:blank] }</code> or <code>{ :input =&gt; [:inclusion] }</code>?</p>