# How to Loop through mulitple field data no model

**URL:** <https://www.ruby-forum.com/t/how-to-loop-through-mulitple-field-data-no-model/142833>\
**Category:** Rails\
**Created:** [July 11, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/how-to-loop-through-mulitple-field-data-no-model/142833 "2008-07-11T22:37:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 11, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/how-to-loop-through-mulitple-field-data-no-model/142833/1 "2008-07-11T22:37:08Z")

</div>

I am creating a form for users to add part information.  
I want to include 5 text fields to gather part numbers.

The user then submits the forms.

Question: Is there a ruby way to loop through the form fields info and  
extract it on each loop?

Thank you for your time in advance.

Mitch

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 11, 2008, 10:38pm UTC](https://www.ruby-forum.com/t/how-to-loop-through-mulitple-field-data-no-model/142833/2 "2008-07-11T22:38:22Z")

</div>

Mitchell G. wrote:

> I am creating a form for users to add part information.  
> I want to include 5 text fields to gather part numbers.
> 
> The user then submits the forms.
> 
> Question: Is there a ruby way to loop through the form fields info and  
> extract it on each loop?
> 
> Thank you for your time in advance.
> 
> Mitch

To Clarify,

The 5 text fields are for part numbers. The user can enter up to 5 part  
numbers. Then click submit.

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 11, 2008, 11:47pm UTC](https://www.ruby-forum.com/t/how-to-loop-through-mulitple-field-data-no-model/142833/3 "2008-07-11T23:47:31Z")

</div>

On 11 Jul 2008, at 21:38, Mitchell G. wrote:

> >

If the inputs are all names parts[] then params[:parts] will be an  
array containing the 5 entries.

Fred

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 11, 2008, 11:54pm UTC](https://www.ruby-forum.com/t/how-to-loop-through-mulitple-field-data-no-model/142833/4 "2008-07-11T23:54:44Z")

</div>

Frederick C. wrote:

> On 11 Jul 2008, at 21:38, Mitchell G. wrote:
> 
> > >
> 
> If the inputs are all names parts[] then params[:parts] will be an  
> array containing the 5 entries.
> 
> Fred

That makes sense. I will give it a try.

Thanks Fred

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 14, 2008, 8:08pm UTC](https://www.ruby-forum.com/t/how-to-loop-through-mulitple-field-data-no-model/142833/5 "2008-07-14T20:08:42Z")

</div>

On Jul 14, 6:44 pm, Mitchell G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Thanks Fred
> 
> I tried to user the following for the inputs  
> \<%=text\_field\_tag item[] %\>
> 
> But I get teh following error

well yes, there is no local variable called item. You need to pass  
text\_field\_tag the name you want ie ‘item[]’

Fred

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 14, 2008, 7:44pm UTC](https://www.ruby-forum.com/t/how-to-loop-through-mulitple-field-data-no-model/142833/6 "2008-07-14T19:44:02Z")

</div>

Mitchell G. wrote:

> Frederick C. wrote:
> 
> > On 11 Jul 2008, at 21:38, Mitchell G. wrote:
> > 
> > > >
> > 
> > If the inputs are all names parts[] then params[:parts] will be an  
> > array containing the 5 entries.
> > 
> > Fred
> 
> That makes sense. I will give it a try.
> 
> Thanks Fred

I tried to user the following for the inputs  
\<%=text\_field\_tag item[] %\>

But I get teh following error

undefined local variable or method `item’ for  
#\<#Class:0x35167bc:0x3516780\>

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 14, 2008, 9:39pm UTC](https://www.ruby-forum.com/t/how-to-loop-through-mulitple-field-data-no-model/142833/7 "2008-07-14T21:39:15Z")

</div>

Frederick C. wrote:

> On Jul 14, 6:44ï¿½pm, Mitchell G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > > Thanks Fred
> > 
> > I tried to user the following for the inputs  
> > ï¿½ ï¿½ ï¿½ ï¿½ ï¿½ ï¿½\<%=text\_field\_tag ï¿½item[] %\>
> > 
> > But I get teh following error
> 
> well yes, there is no local variable called item. You need to pass  
> text\_field\_tag the name you want ie ‘item[]’
> 
> Fred

Thanks Fred, sorry about the dumb question. I have that working now.

Thanks again,

Mitch
