默认情况下调用rails.model.to_json我如何定制Rails 3验证错误json输出?
将显示是这样的:
{"name":["can't be blank"],"email":["can't be blank"],"phone":["can't be blank"]}
相反的消息,我需要生成可服务客户端上使用的一些状态代码:
[{"field": "name", "code": "blank"}, {"field": "email", "code": "blank"}]
此方法与github api v3错误非常相似 - http://developer.github.com/v3/
我该如何使用Rail S'
另一个类似的问题。 http://stackoverflow.com/questions/5911470/api-errors-customization-for-rails-3-like-github-api-v3。也没有答案= \ –
在这个线程中,rails“响应者”用于实现这一点。 http://stackoverflow.com/questions/5911470/api-errors-customization-for-rails-3-like-github-api-v3 –