Re: Trouble with multiple fields

Mike DeGraw-Bertsch
Sun, 23 Oct 2005 18:45:19 -0000

Howdy,

Okay, I can work with that. However, how do I then use error_message_on or
error_messages_for? Doesn''t it expect instance variables? @people is
just a
hash, and it won''t recognize ''person''.

Thanks,
-Mike


On 10/23/05, Steve Prentice <
prentice-p8dDKEW+AByWw5T4fKrT70EOCMrvLtNR@public.gmane.org>
wrote:
>
> Wouldn''t this work:
>
> i = 0
> @people.each do |person|
> <text_field "person", "name", "index"
=> i++>
> end
>
>
> On Sun, 2005-10-23 at 11:51 -0400, Mike DeGraw-Bertsch wrote:
> > 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
> > http://lists.rubyonrails.org/mailman/listinfo/rails
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


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