accepts_nested_attributes_forで子から親もまとめて作成できる

ポイントは2つ
①子のモデルにaccepts_nested_attributes_forを定義

class Child
  belongs_to :parent
  accepts_nested_attributes_for :parent
end

②fields_forで親のフィールドオブジェクトを生成する際に親のフィールドのname属性を自力で指定する。
親から子の場合、自動で語尾に_attributesと付くが、子から親の場合何故か付かないので自力で_attributesを指定する。

<%= f.fields_for 'parent_attributes', @child.parent do |parent_f| %>
<% end %>