I happen to maintain an open source app that basically has this exact scenario, we’re creating a User and an Account at the same time, and it was using accepts_nested_attributes_for
. I’ve opened a PR on our app with a bit more full fledged example:
It includes (pretty basic) specs and shows how to promote child errors, allowing you to validate things like uniqueness etc.
Although I do kind of like this approach, it is quite a lot more code (~50 lines without tests)