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
(http://railscasts.com/episodes/73) 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|
%>


Person:
<%= collection_select(:pp, :person_id, Person.get_list, :id,
:nom, {:prompt => ‘Person?’}) %>
Role:
<%= select(:pp, :role, Person::ROLE_NAMES, {:prompt => ‘Role?’})
%>


<% end %>
<% end %>

<% end %>

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

Rather than this:


(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 P.
Research Analyst/Programmer
Group Health Center For Health Studies (Cancer Research Network)
(206) 287-2078
Google Talk: rpardee

On May 2, 1:52 pm, “Pardee, Roy” [email protected] wrote:

  </p>

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?

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


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?’}) %>


<% end %>
<% end %>

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

Role:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs