Trouble with multiple fields

Mike DeGraw-Bertsch
Sun, 23 Oct 2005 15:51:17 -0000

Howdy,

Reading about the "index" option for checkboxes and text fields, I
understand that it will create values like this:

<text_field "person", "name", "index" =>
1>

becomes

<input type="text" id="person_1_name"
name="person[1][name]" value="<%= @
person.name <http://person.name> %>"/>

However, shouldn''t it really evaluate to this instead:

<input type="text" id="person_1_name"
name="person[1][name]" value="<%@person[1].name
%>"/>

I''ve been losing my mind over this. In my program, @person is a hash,
so
@person[1].name resolves very nicely, but @person.name
<http://person.name>simply disappears. Do I write a horrible hack that
says "@
person.name <http://person.name> = @person[1].name" before each field
is
printed? That just seems so ugly. I''m hoping there''s an easy,
obvious way
that I''m missing.

Another thought I had is extending FormHelper to do this for me. Looking at
its code, it seems my problem lies here:

def object
@template_object.instance_variable_get "@#{@object_name}"
end

Would I want to change object to be something like:

def object(*index)
if (!index)
return @template_object.instance_variable_get "@#{@object_name}"
else
return @template_object.instance_variable_get
"@#{@object_name}[#{index}]"
end
end

Hoping I missed something really obvious, or that the above extension
isn''t
lunatic.

-Mike


_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org