Created
June 13, 2017 10:39
-
-
Save mazikwyry/308021e8ef642579efd576b8a01e8788 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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