Home rails 4.2 upgrade broke json rendering
Reply: 0

rails 4.2 upgrade broke json rendering

user836 Published in July 17, 2018, 3:25 pm

I tried upgrading my rails app from rails 4.1.0 => 4.2.7 but found that it broke my JSON views. In particular, ActiveRecord objects no longer render correctly.

For instance: Model.first.to_json in rails console now produces "#\u003cModel:0x007f9208c904e0\u003e", rather than valid JSON as before. Model.first.as_json works correctly, but for some reason, it seems to_json is calling to_s instead.

I tried overriding the ActiveSupport encoder but it didn't help, and am pretty stumped. Any ideas?

(UPDATE: I also noticed Time.now.utc.to_json changed from 2017-12-07T19:38:47Z => 2017-12-07 19:37:55 UTC, the latter being == time.as_json and the former == time.to_s)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.438828 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO