Module: ApiGuard::ResponseFormatters::Renderer

Defined in:
lib/api_guard/response_formatters/renderer.rb

Instance Method Summary collapse

Instance Method Details

#render_error(status, options = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/api_guard/response_formatters/renderer.rb', line 11

def render_error(status, options = {})
  data = { status: I18n.t('api_guard.response.error') }
  data[:error] = options[:object] ? options[:object].errors.full_messages[0] : options[:message]

  render json: data, status: status
end

#render_success(data: nil, message: nil) ⇒ Object



4
5
6
7
8
9
# File 'lib/api_guard/response_formatters/renderer.rb', line 4

def render_success(data: nil, message: nil)
  resp_data = { status: I18n.t('api_guard.response.success') }
  resp_data[:message] = message if message

  render json: resp_data, status: 200
end