I use the pedigree to create a goal tree. I would like to send the contents of this tree to the browser using json.
My controller looks like this:
@goals = Goal.arrange respond_to do |format| format.html
When I open the json file, I get this output:
{"#<Goal:0x7f8664332088>":{"#<Goal:0x7f86643313b8>":{"#<Goal:0x7f8664331048>":{"#<Goal:0x7f8664330c10>":{}},"#<Goal:0x7f8664330e68>":{}},"#<Goal:0x7f86643311b0>":{}},"#<Goal:0x7f8664331f70>":{},"#<Goal:0x7f8664331d18>":{},"#<Goal:0x7f8664331bd8>":{},"#<Goal:0x7f8664331a20>":{},"#<Goal:0x7f86643318e0>":{},"#<Goal:0x7f8664331750>":{},"#<Goal:0x7f8664331548>":{"#<Goal:0x7f8664330aa8>":{}}}
How can I render the contents of Goal objects in a json file?
I tried this:
@goals.map! {|goal| {:id => goal.id.to_s}
but it does not work since @goals is an ordered hash.
json ruby-on-rails-3 ancestry
Johan hovda
source share