Ben Anderson
2005-Nov-24 13:52 UTC
Re: <%= text_field("order[]item[]", ''@item'') %> (working on it)
ok, so I''m playing with the source now and have gotten this working
(at least on the output side of things).
So my example of:
<% for @order in @orders %>
...
<%= text_field("order[]", ''name'') %>
...
<% for @item in @order.items %>
...
<%= text_field("order[]item[]", ''name'') %>
yeilds something like this:
<input type="text" name="order[1][name]" ...
<input type="text" name="order[1]item[1][name]"...
<input type="text" name="order[2][name]" ...
<input type="text" name="order[2]item[1][name]"...
<input type="text" name="order[2]item[2][name]"...
Before I start working on loading this back into model objects upon a
submit, does anyone have any thoughts on this approach? This
functionality wasn''t left out for any particular reason, was it?
Thanks,
Ben
On 11/23/05, Rick Olson
<technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On 11/23/05, Ben Anderson
<benanderson.us-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Not too sure what you mean here... Do you mean to pass in exactly the
> > name and id that I want? I figured I could that if I wanted to. I
> > was looking for something that works seamlessly and that loads back in
> > via an incoming request. Seems like it would just take extending
> > what''s already there for the one level.
> >
> > Unless I''m missing what you''re saying and
there''s some magic to
> > text_field_tag that I''m missing?
> >
> > -Ben
>
> Actually, you had it right. I went to check the docs :)
>
> http://rails.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html
>
> Apparently you can do <%= text_field ''order'',
''name'', :index => 1 %>
> which will give you an id like order[1][name]. Do your looping like
> this:
>
> <% @orders.each_with_index do |order, order_index| -%>
>
> Beyond that I''m not quite sure. Never had to do this actually.
>
> --
> rick
> http://techno-weenie.net
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>