Module: Restful::Jsonapi::SerializableErrors
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/restful/jsonapi/serializable_errors.rb
Instance Method Summary collapse
Instance Method Details
#serializable_errors(object) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/restful/jsonapi/serializable_errors.rb', line 6 def serializable_errors(object) errors = object.errors prefix = object.class.to_s.demodulize.underscore json = {} new_hash = errors.to_hash.map do |k, v| v.map do |msg| { id: "#{prefix}.#{k}", title: msg } end end.flatten json[:errors] = new_hash json end |