names of select elements inside a fields_for block not generated as expected

Hey All,

I'm trying to play along w/the 'complex forms 1' railscast (#73 Complex Forms Part 1 - RailsCasts) and having trouble. The view is projects/new. I'm trying to add some project_people to the form w/code like so:

<% form_for(@project) do |f| %>

  [project stuff here]

  <% for pp in @project.project_person %>     <% fields_for 'project[proj_people_attributes]', pp do |pp_form| %>       <p>         Person:         <%= collection_select(:pp, :person_id, Person.get_list, :id, :nom, {:prompt => 'Person?'}) %>         Role:         <%= select(:pp, :role, Person::ROLE_NAMES, {:prompt => 'Role?'}) %>       </p>     <% end %>   <% end %>

<% end %>

I get the expected series of 3 <select>s, but their names are not automatically indexed. So I get:

  <select id="pp_person_id" name="pp[person_id]">   <select id="pp_role" name="pp[role] ">

Rather than this:

  <select id="pp_person_id" name="project[proj_people_attributes][1][person_id]">   <select id="pp_role" name="project[proj_people_attributes][1][role] ">

(At least I *think* that's what they should be.)

Now, you may be saying to yourself "he's got to call those select helpers on the pp_form object that the fields_for block yields." If I do that, I get (e.g.): undefined method `merge' for :nom:Symbol. So are there different select helpers for using inside fields_for?

Many thanks!

-Roy

Roy Pardee Research Analyst/Programmer Group Health Center For Health Studies (Cancer Research Network) (206) 287-2078 Google Talk: rpardee

Nevermind--got it. I *do* have to call those methods on pp_form, and when I do, I've got to leave out that first argument that I'd been using to specify the object whose attribute is to be modified. Which makes sense, since the yeilded form helper thingy is already tied to a particular object. So This works:

  <% for pp in @project.project_person %>     <% fields_for 'project[proj_people_attributes]', pp do |pp_form| %>       <p>         Person:         <%= pp_form.collection_select(:person_id, Person.get_list, :id, :nom, {:prompt => 'Choose a person'}) %>         Role:         <%= pp_form.select(:role, Person::ROLE_NAMES, {:prompt => 'Role?'}) %>       </p>     <% end %>   <% end %>

Also--FWIW--those names get generated with empty array brackets, like so:

Role: <select id="project_proj_people_attributes__role" name="project[proj_people_attributes][role]"> </select>

I guess they get gathered up into a real array w/real indices at the routing stage?

At any rate, I'm off and running again...

Cheers,

-Roy