Create and join two models in one form (HABTM)

What is the best approach for using one form to create two different
models and join them? I'm working with a HABTM relationship. For
example a project HABTM services and vice versa.

I've tried using accepts_nested_attributes_for which seems to work when
I'm creating a project and using a service that already exists. When
the service is new it tries to join the newly created service before the
project has an id, giving a null key in the SQL.

I'm still learning these less obvious parts of Rails and this has been a
big brick wall for me. I would greatly appreciate any help.