# Html forms, arrays, and controllers

**URL:** <https://www.ruby-forum.com/t/html-forms-arrays-and-controllers/115818>\
**Category:** Rails\
**Created:** [September 28, 2007, 7:47pm UTC](https://www.ruby-forum.com/t/html-forms-arrays-and-controllers/115818 "2007-09-28T19:47:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [September 28, 2007, 7:47pm UTC](https://www.ruby-forum.com/t/html-forms-arrays-and-controllers/115818/1 "2007-09-28T19:47:26Z")

</div>

hey guys,

I’ve searched around and haven’t been able to turn up much. Here is  
the gist of what I need to accomplish. I need to be able to pass a  
view generated array to a controller for processing. Basically a  
varying amount of ids… sometimes 1 sometimes 10.

Has anyone every done something similar? I will be glad to divulge my  
details if this is to vague.

Thanks,

Ken

---

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [September 28, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/html-forms-arrays-and-controllers/115818/2 "2007-09-28T20:18:32Z")

</div>

You name the elements with []'s like this:

\<%= check\_box\_tag “colors[red]”, 1, false, :id =\> ‘colors\_red’ -%\>  
\<%= check\_box\_tag “colors[blue]”, 1, false, :id =\> ‘colors\_blue’ -%\>  
\<%= check\_box\_tag “colors[green]”, 1, false, :id =\> ‘colors\_green’ -%\>

Then in your controller, checked boxes will be available as:

params[:colors][:red], parmas[:colors][:blue], etc

predhme wrote:

> Thanks,
> 
> Ken
> 
> >

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [September 28, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/html-forms-arrays-and-controllers/115818/3 "2007-09-28T21:08:31Z")

</div>

If you want to do it the way I showed, you need to use text\_field\_tag  
not text\_field. text\_field and the other \_field helpers are designed to  
be used with a specific object where there \_tag brothers are designed to  
generate tags not based on a specific object.

predhme wrote:

> >

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [September 28, 2007, 9:20pm UTC](https://www.ruby-forum.com/t/html-forms-arrays-and-controllers/115818/4 "2007-09-28T21:20:16Z")

</div>

Interesting. I will have to play around with that. Thanks much.

---

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [September 28, 2007, 9:03pm UTC](https://www.ruby-forum.com/t/html-forms-arrays-and-controllers/115818/5 "2007-09-28T21:03:50Z")

</div>

thanks, your response helped…

basically i used a

\<%= text\_field “item” “first\_item” %\>  
\<%= text\_field “item” “second\_item” %\>

for whatever reason it wouldn’t allow me to do a item[first] for the  
name as you suggested. it claimed that @item[] cannot be used for an  
instance variable name. but i have it working now. thanks again.

---

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [September 29, 2007, 3:54am UTC](https://www.ruby-forum.com/t/html-forms-arrays-and-controllers/115818/6 "2007-09-29T03:54:07Z")

</div>

predhme wrote:

> hey guys,
> 
> I’ve searched around and haven’t been able to turn up much. Here is  
> the gist of what I need to accomplish. I need to be able to pass a  
> view generated array to a controller for processing. Basically a  
> varying amount of ids… sometimes 1 sometimes 10.
> 
> Has anyone every done something similar? I will be glad to divulge my  
> details if this is to vague.

The :index option for form helpers might be useful.

> **[ActionView::Helpers::FormHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html)**
>
> Form helpers are designed to make working with resources much easier compared to using vanilla HTML.

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)
