I have an Item class that also contains many items (using has_many). What I want to do is read all items that have no parent (the top level) and all their subitems. So basically I need my entire Item table nested correctly, into json.
This is the code I'm using right now, but this only returns the top level items and their items, it doesn't go any lower than that. (So I'm left with only two levels)
@items = Item.where("item_id IS ?" , nil).order("position")
respond_to do |format|
format.json { render :json => @items.to_json(:include => :items)}
end