html forms, arrays, and controllers

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.



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, 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.

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:

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