In your controller
class ParentsController < ApplicationController def edit @parent = Parent.find(params[:id]) @child = @parent.child.build end end
In your opinion
<%= form_for @parent, do |f| %> <%= f.text_field :name %> <%= f.fields_for @child do |builder| %> <%= builder.text_field :name %> <% end %> <%= f.submit "Save" %> <% end %>
Assuming parent_name and child_name were here to illustrate your needs. Your attributes should not be positioned like this.
You also need to pass id in a permit method like this
child_attributes: [:id, :name]
Or using child_name
child_attributes: [:id, :child_name]
This is currently not well documented.
source share