# Creating Multiple Child objects on a single form

**URL:** <https://www.ruby-forum.com/t/creating-multiple-child-objects-on-a-single-form/62098>\
**Category:** Rails\
**Created:** [May 31, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/creating-multiple-child-objects-on-a-single-form/62098 "2006-05-31T15:38:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Kolk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e8cbc/32.png) [@Kevin\_Kolk](https://www.ruby-forum.com/u/Kevin_Kolk)\
**Post date:** [May 31, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/creating-multiple-child-objects-on-a-single-form/62098/1 "2006-05-31T15:38:27Z")

</div>

I’ve been trying to solve this for the last few hours and I have  
something that is working now but I’m curious if there isn’t a better  
‘right’ way to do it since this seems a bit of a cludge to me, but I  
haven’t find a better way to make it work.

The models are as follows:

Goals, which have multiple objectives.  
Goals also have multiple evaluations of those objectives through status  
models.

So, I’m trying to create a form for doing the evaluations, which ideally  
would allow you to set the status of all objectives in a single view.

My view looks like this (trimmed down a bit for easier posting):

```
<% for objective in @goal.objectives %>
   <label for="status<%= objective.number %>_status">Status:</label>
     <%= text_field 'status' + objective.number.to_s, 'status' %>
     <%= hidden_field 'status' + objective.number.to_s, 

```

‘objective\_id’, :value =\> objective.id %\>  
\<% end %\>

```
<label for="evaluation_date">
        Evaluation Date:</label>
<%= date_select 'evaluation', 'evaldate', :order => [:day, :month, 

```

:year ] %\>  
  
Comments:  
\<%= text\_area ‘evaluation’, ‘comment’ %\>

This produces a set of ‘status’ objects like status1, status2, status3  
in params, which I then loop through again in the create function in my  
evaluations controller:

def create  
@evaluation = Evaluation.new(params[:evaluation])  
@goal = Goal.find\_by\_id(params[:goal\_id])  
if @evaluation.save  
for objective in @goal.objectives  
@evaluation.statuses.create(params[‘status’ +  
objective.number.to\_s])  
end  
flash[:notice] = ‘Evaluation was successfully created.’  
redirect\_to :action =\> ‘show’, :controller =\> ‘goals’, :id =\>  
@goal  
else  
render :action =\> ‘new’  
end  
end

So, this works fine, but I’m curious if there is a better way to do  
this.

---

<div class="post-metadata">

**Author:** ![Kevin\_Kolk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e8cbc/32.png) [@Kevin\_Kolk](https://www.ruby-forum.com/u/Kevin_Kolk)\
**Post date:** [May 31, 2006, 4:12pm UTC](https://www.ruby-forum.com/t/creating-multiple-child-objects-on-a-single-form/62098/2 "2006-05-31T16:12:12Z")

</div>

## This may help … [http://rorsublist.rubyforge.org/](http://rorsublist.rubyforge.org/)

View this message in context:  
[http://www.nabble.com/Creating+Multiple+Child+objects+on+a+single+form-t1710645.html#a4644890](http://www.nabble.com/Creating+Multiple+Child+objects+on+a+single+form-t1710645.html#a4644890)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).
