I just started using Ancestry instead of awesome_nested_set, and I would like to create a nested form so that I can create a parent account and many child accounts all in one form. The problem is that Ancestry does not allow you to create a child for the new parent.
In awesome_nested_set, I could do this in the rails console
a = Account.new
a.children.build
When I type a.children, I see that this new child is present, although the parent of my account has not yet been created. This allowed me to display the form with the parent account and several empty children, then on submitting I would simply ignore all empty children and create the whole batch.
If I try to do the same using ancestors, I get the following error:
a=Account.new
a.children
Ancestry::AncestryException: No child ancestry for new record. Save record before performing tree operations.
from /home/map7/.rvm/gems/ruby-1.9.2-p180/gems/ancestry-1.2.4/lib/ancestry/instance_methods.rb:62:in `child_ancestry'
from /home/map7/.rvm/gems/ruby-1.9.2-p180/gems/ancestry-1.2.4/lib/ancestry/instance_methods.rb:132:in `child_conditions'
from /home/map7/.rvm/gems/ruby-1.9.2-p180/gems/ancestry-1.2.4/lib/ancestry/instance_methods.rb:136:in `children'
from (irb):8
from /home/map7/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from /home/map7/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from /home/map7/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
?
, ?