Saving parent and child same time nested form

Hello, I am new to rails and I am building web app that has character types and every character type can have attributes. Currently logedin users can make character type and then on edit page add new attributes which is done using jquery and ajax. I would like to add feature to be able to add attributes when creating character type at the same time. I tried putting in new.html.erb page same code which I use in edit page but I keep getting error because character type does not exist yet. This is line of code how I make new attribute: <%= render 'character_attributes/form', character_attribute:, remote: true %> I am using nested form, I tried to google and add stuff to my models, controllers to try to make this work but I keep getting errors,

No route matches {:action=>"index", :character_type_id=>#<CharacterType id: nil, user_id: nil, name: nil, created_at: nil, updated_at: nil>, :controller=>"character_attributes", :format=>nil}, possible unmatched constraints: [:character_type_id]

or error: You cannot call create unless the parent is saved if I try using @character_type.character_attributes.create! in my new method in character_attributes controller. Could anyone please tell me where and what to change to make this work? Thank you