Skip to content

Instantly share code, notes, and snippets.

@mazikwyry
Created June 13, 2017 10:39
Show Gist options
  • Save mazikwyry/308021e8ef642579efd576b8a01e8788 to your computer and use it in GitHub Desktop.
Save mazikwyry/308021e8ef642579efd576b8a01e8788 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::API
def render_resource(resource)
if resource.errors.empty?
render json: resource
else
validation_error(resource)
end
end
def validation_error(resource)
render json: {
errors: [
{
status: '400',
title: 'Bad Request',
detail: resource.errors,
code: '100'
}
]
}, status: :bad_request
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment