在控制器中:
if @topic.save
render json: @topic, status: :updated, location: @topic
else
render json: @topic.errors, status: :unprocessable_entity
end
如果出现错误,json响应如下:
{"topic_id":["has already been taken"]}
如何为错误的json响应添加分组前缀,以便在客户端(RestKit)路径映射上更容易解析? e.g:
{"errors":[{"topic_id":["has already been taken"]}]}