class Node < ActiveRecord::Base attr_accessible :name belongs_to :parent_node, :class_name => "Node", :foreign_key => :parent_id has_many :child_nodes, :class_name => "Node", :foreign_key => :parent_id end
For the root node, parent_id will be nill. Say I have the id of the root node, and wish to print the entire tree to the output stream in json format.
How do I go about doing that?
Assume the tree does not contain any loops.