Topic: Creating children with reference to parent
An extremely dumb question.
I've got a model "parent", and a model "child".
Parent has_many children.
Child belongs_to parent.
All the foreign keys are set up correctly, and I know that it is possible to do the creation because I initially coded the admin system using the sub_list plugin, which created children just fine. But now I've decided I don't like this style of doing things, because my object structure is deeply nested and the admin form get really unwieldy from a usability point of view.
So, I'd like to take a much simpler approach, and have two forms. I want to make the form that allows me to create children as its own separate "new" form.
My big dumb question: how do i pass the reference to the parent so that the child can save itself properly?
For the "new" method in the child controller, i've got
@child = Child.new
@parent = Parent.find(params[:parent])
This part works fine (e.g. @parent.title displays correctly in the page), but when i go to save the child, the @parent goes away, so i get a foreign key violation. Is there some way i need to store the value of @parent in the page so it can get passed back to the child_controller's "create" method?
This is perhaps the dumbest question I have ever asked in a forum, but I am quite honestly stumped as to how to do this.