app/controllers/parents_controller.rb
class ParentsController < ApplicationController
def new
@parent = User.new
2.times {@parent.kids.build}
# This creates a new, empty Parent instance and two empty kid instances belonging to the Parent.
end
def create
@parent = Parent.create(parent_params)
if @classroom.save
redirect_to parent_path(@parent) # Only if you already have a parents/show
else
render ‘new’
end
end
private
def parent_params
params.require(:parent).permit(:any_parent_attributes_go_here kids_attributes: [:id, :name, :_destroy]) # This permits the kids params to be saved
end
end