# Multi-model forms

**URL:** <https://www.ruby-forum.com/t/multi-model-forms/154767>\
**Category:** Rails\
**Created:** [December 3, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/multi-model-forms/154767 "2008-12-03T18:27:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveelman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bcef8e/32.png) [@daveelman](https://www.ruby-forum.com/u/daveelman)\
**Post date:** [December 3, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/multi-model-forms/154767/1 "2008-12-03T18:27:52Z")

</div>

Hi

I’m trying to implement multi-model forms. Specifically a form  
containing the following relationships …

```
parent -> children

child -> grandchildren

[ NOTE : "->" denotes a one to many relationship / association -

```

the ‘\>’ points to the many ]

Recipe #13 in Advanced Rails Recipes does a great job of explaining  
how to implement the parent -\> children relationship using Project  
and Tasks. Specifically …

```
  project -> tasks (using my "->" nomenclature)

```

I’d like to include an additional model - for example adding  
“Participants” to the above example …

```
  project -> tasks

  task -> participants

```

Where I’m getting stuck is what to use for the ‘prefix’ (using the  
terminology of Recipe #13) - or what name to use to refer to  
‘participants’, in such a way that the params hash is properly  
populated for ‘auto-population’ by the controller?

Using the Project/Task metaphor and extending it to include the  
relationship that a Task has many Participants, the ‘task’ partial  
would look something like this (not in its final form - but early on  
in the development of a +2 model multi-model form. Also note the  
‘???’) …

 \<% fields\_for "project[task\_attributes][]", task do |f| %\> 

Task: \<%= f.text\_field :name %\>

```
<% 3.times { task.participants.build } %>

<% for participant in task.participants %>

  <% fields_for "project[???????]", participant do |p_form| %>
    <p>
      Participant Name: <%= p_form.text_field :name %>
    </p>
  <% end %>
<% end %>

```

\<% end %\>

I’m assuming that a Task can have at most 3 participants, like what  
was done in the early iterations of Ryan Bate’s original screen-cast.

I’m trying to figure out how to name the ‘grandchildren’ such that  
the params hash is correctly populated ? Specifically - what to put  
in place of the ‘???’ in this line …

```
<% fields_for "project[???????]", participant do |p_form| %>

```

If the solution doesn’t involve replacing the ‘???’ above -  
please point me in the right direction by providing as much detail /  
info as you have time for.

I’m grateful for any help / guidance you can provide.

Thanks  
Dave
