从 Web 服务应用程序检索错误数据
我正在使用 Ruby on Rails 3,并且在发出 HTTP POST 请求后尝试从 Web 服务应用程序检索错误数据。我想接收包括 errors
根在内的数据。
在服务应用程序控制器中,我
format.json {
render :json => @account.errors, :status => 202
}
返回了返回数据,例如,
{\"base\":\"Invalid submitting\",\"name\":\"To short\"}
我想接收这样的返回数据
# Note 'errors'
"{\"errors\":{\"base\":\"Invalid submitting\",\"name\":\"To short\"}"}
我怎样才能做到这一点?
解决方案是这样做
render :json => '{"errors":' + @account.errors.to_json + '}'
,但我不认为这是正确\正确的方法。 RoR 当然有一些功能可以做得更好......
I am using Ruby on Rails 3 and I am trying to retrieve error data from a web service application after making to that an HTTP POST request. I would like to receive that data including the errors
root.
In a service app controller I have
format.json {
render :json => @account.errors, :status => 202
}
The return data returned, for example, is
{\"base\":\"Invalid submitting\",\"name\":\"To short\"}
I would like to receive back data like this
# Note 'errors'
"{\"errors\":{\"base\":\"Invalid submitting\",\"name\":\"To short\"}"}
How can I make that?
A solution is to make this
render :json => '{"errors":' + @account.errors.to_json + '}'
but I don't think it is the right\correct way. RoR certainly has some features to do that better...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够构造一个等效的哈希,然后使用它:
You should be able to construct an equivalent hash and then use that: