Getting Ruby error "You cannot call create unless the parent is saved" -
i've read through several resources not having luck finding answer. have following line of code, returns "you cannot call create unless parent saved":
test.entries.create!({ :date => date, :volume => 15 }) above line of code, have this:
1.upto(5) |i| test = test.create( :name => "test #{i}" ) both of these scripts encapsulated inside 1 large loop. script creates test , creates entry on test using test.entries.create!.
however, script failing out because parent has not been saved. understanding .create! .new , .save, initial test should saved. have tried manually putting in test.save before error no luck. thoughts?
what test in second block of code. mean test.create? also, there validations might preventing save happening?
try adding create! test.create instead raises exception if there errors.
Comments
Post a Comment