开发者

rails to_json incorrectly converting hash

开发者 https://www.devze.com 2023-03-14 05:43 出处:网络
I think I found a bug with the to_json method in Rails. I have generated a fresh scaffold and modified the create method to render the errors in JSON format.

I think I found a bug with the to_json method in Rails.

I have generated a fresh scaffold and modified the create method to render the errors in JSON format.

The to_json method is removing the array from the returned hash.

Here is the result of a debug session.

(rdb:2) @recipe.errors {:name=>["can't be blank"]}

(rdb:2) @recipe.errors.to_json "{\"name\":\"can't be b开发者_如何学JAVAlank\"}"

As you can see, the array has been removed.

Has anyone else found this?

Cheers,

Tim


irb(main):003:0> {:name=>["can't be blank"]}.to_json
=> "{"name":["can't be blank"]}"

I use ruby1.9.2, and I don't find the bug above. May be the problem has been resolved:)

0

精彩评论

暂无评论...
验证码 换一张
取 消