I want to customize the error response of respond_with
. The way it renders errors is like this:
# /app/controllers/articles_controller.rb
def create
article = Article.new(params[:article])
article.save
respond_with(article)
end
Response:
{
errors: {
title: ["can't be blank", "must be longer than 10 characters"],
body: ["can't be blank"]
}
}
I would like to have it respond in a different way. Is there any way to override this format?
I've successfully done this by monkey patching the ActionController::Responder class and redefining json_resource_errors
but this seems like a bad way to do this.
The easiest way would be to not use
respond_with
butrespond_to
(docs).