# Names of select elements inside a fields\_for block not generated as expected

**URL:** <https://www.ruby-forum.com/t/names-of-select-elements-inside-a-fields-for-block-not-generated-as-expected/136514>\
**Category:** Rails\
**Created:** [May 2, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/names-of-select-elements-inside-a-fields-for-block-not-generated-as-expected/136514 "2008-05-02T22:52:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [May 2, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/names-of-select-elements-inside-a-fields-for-block-not-generated-as-expected/136514/1 "2008-05-02T22:52:26Z")

</div>

Hey All,

I’m trying to play along w/the ‘complex forms 1’ railscast  
([#73 Complex Forms Part 1 - RailsCasts](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

---

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [May 2, 2008, 11:42pm UTC](https://www.ruby-forum.com/t/names-of-select-elements-inside-a-fields-for-block-not-generated-as-expected/136514/2 "2008-05-02T23:42:59Z")

</div>

On May 2, 1:52 pm, “Pardee, Roy” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
