Module: Desponders::ErrorResponder

Defined in:
lib/desponders/error_responder.rb

Instance Method Summary collapse

Instance Method Details

#lookup_messageObject



15
16
17
18
19
20
21
# File 'lib/desponders/error_responder.rb', line 15

def lookup_message
  action  = controller.action_name
  lookup  = ['errors', action].join('.').to_sym
  options = { resource_name: resource.class.model_name.human }

  I18n.t(lookup, options)
end

#to_formatObject

If it isn’t a get request and the response model has errors it automatically renders json with errors



5
6
7
8
9
10
11
12
13
# File 'lib/desponders/error_responder.rb', line 5

def to_format
  if has_errors?
    controller.render json: {
      message: lookup_message, errors: resource.errors
    }, status: :unprocessable_entity
  else
    super
  end
end