rails to_json incorrectly converting hash
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:)
精彩评论