Creating Multiple Child objects on a single form


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

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 => %>
<% end %>

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

:year ] %>

<%= 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])
@goal = Goal.find_by_id(params[:goal_id])
for objective in @goal.objectives
@evaluation.statuses.create(params[‘status’ +
flash[:notice] = ‘Evaluation was successfully created.’
redirect_to :action => ‘show’, :controller => ‘goals’, :id =>
render :action => ‘new’

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


This may help …

View this message in context:
Sent from the RubyOnRails Users forum at