module Restful::Jsonapi::SerializableErrors

Public Instance Methods

serializable_errors(object) click to toggle source
# File lib/restful/jsonapi/serializable_errors.rb, line 6
def serializable_errors(object)
  prefix = object.class.to_s.demodulize.underscore

  errors = object.errors.to_hash.each_with_object([]) do |(k, v), array|
    v.each do |msg|
      array.push(id: "#{prefix}.#{k}", title: msg)
    end
  end

  { errors: errors }
end