Forum: Ruby on Rails Multi-model forms

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dave E. (Guest)
on 2008-12-03 19:27
(Received via mailing list)

  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
'??????') ...

<div class="task">
  <% fields_for "project[task_attributes][]", task do |f| %>
      Task: <%= f.text_field :name %>

    <% 3.times { } %>

    <% for participant in task.participants %>

      <% fields_for "project[???????]", participant do |p_form| %>
          Participant Name: <%= p_form.text_field :name  %>
      <% 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.

This topic is locked and can not be replied to.