ruby - How to read/write a collection of objects as json -


i have collection of user classes want save json file.

users = [] users << user.new('john', 'smith', 55)  file.open("users.json", "w") |f|   f.write(json.pretty_generate(users) end 

the problem user isn't being json'ified, saving file like:

[   "#<user:0x000000101010eff40>",   .. ] 

also, how read json file collection?

the problem is, users variable still array of activerecord objects. need convert them json.

users = [] users << user.new('john', 'smith', 55)  file.open("users.json", "w") |f|   f.write(json.pretty_generate(users.to_json) end 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -