# Multiple text fields all with the same method

**URL:** <https://www.ruby-forum.com/t/multiple-text-fields-all-with-the-same-method/73624>\
**Category:** Rails\
**Created:** [October 25, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/multiple-text-fields-all-with-the-same-method/73624 "2006-10-25T20:10:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 25, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/multiple-text-fields-all-with-the-same-method/73624/1 "2006-10-25T20:10:24Z")

</div>

I have 3 text fields in a form , all with the same method, since those  
params will  
be inserted via a loop which is set up in the create action.  
However, I’m noticing that the form is only sending through the 1st  
value  
and leaving out the additional 2.

In my form I have this:  
\<%= text\_field(:cantitle, :title\_opt)%\>  
\<%= text\_field(:cantitle, :title\_opt)%\>  
\<%= text\_field(:cantitle, :title\_opt)%\>

Even though I put input into each , the params came through as such:  
{“cantitle”=\>{“title\_opt”=\>“CEO”}, # so the 2nd and 3rd were skipped.

In the controller I have this loop- # which if 3 values were submitted ,  
3  
records would be created.  
a = (params[:cantitle][:title\_opt])  
a.each {|x|  
cantitle = Cantitle.new  
cantitle.title\_opt = x  
cantitle.save }

Any ideas how to get each value through ? Also, I’m wondering what would  
happen if someone filled in the 1st and 3rd box and left the 2nd blank.  
Do  
I have to account for a null value ?

## Stuart

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 25, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/multiple-text-fields-all-with-the-same-method/73624/2 "2006-10-25T20:42:27Z")

</div>

It is not possible to have same name for all the fields, that’s why only  
one  
field is getting populated.

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 25, 2006, 9:52pm UTC](https://www.ruby-forum.com/t/multiple-text-fields-all-with-the-same-method/73624/3 "2006-10-25T21:52:39Z")

</div>

Bala, thanks - you always come through for me.  
Actually though it is possible (as I just learned) by adding “index” = x

So now I have the text fields as such:  
\<%= text\_field(:cantitle, :title\_opt, “index” =\> 1)%\>  
\<%= text\_field(:cantitle, :title\_opt, “index” =\> 2)%\>  
\<%= text\_field(:cantitle, :title\_opt, “index” =\> 3)%\>

Which get translated into :

And params are such:  
“cantitle”=\>{“1”=\>{“title\_opt”=\>“CEO”}, “2”=\>{“title\_opt”=\>“COO”},  
“3”=\>{“title\_opt”=\>“CIO”}},

Stuart

On 10/25/06, Bala P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> >

–

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 25, 2006, 11:12pm UTC](https://www.ruby-forum.com/t/multiple-text-fields-all-with-the-same-method/73624/4 "2006-10-25T23:12:47Z")

</div>

Great, looks like we can learn a lot from the Rails API.
