Forum: Ruby on Rails ", '@item') %>

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
benanderson.us (Guest)
on 2005-11-23 22:57
(Received via mailing list)
Hi,
Is it possible to do something like this multiple levels deep as shown
in the subject?

<% for @order in @orders %>
  ...
  <%= text_field("order[]", 'name') %>
  ...
  <% for @item in @order.items %>
    ...
    <%= text_field("order[item[]]", 'name') %>

Seems like something along these lines should work.  I've tried a
couple different ways, but I can't guess my way through this.  The
documentation doesn't mention anything, so I'm guessing it's not
implemented?  I'm looking at the source now, so maybe that will help.

Any thoughts?
Thanks,
Ben
technoweenie (Guest)
on 2005-11-23 23:58
(Received via mailing list)
On 11/23/05, Ben A. <removed_email_address@domain.invalid> wrote:
>     <%= text_field("order[item[]]", 'name') %>
>
> Seems like something along these lines should work.  I've tried a
> couple different ways, but I can't guess my way through this.  The
> documentation doesn't mention anything, so I'm guessing it's not
> implemented?  I'm looking at the source now, so maybe that will help.
>

try text_field_tag.  text_field expects an active record model.


--
rick
http://techno-weenie.net
benanderson.us (Guest)
on 2005-11-24 00:18
(Received via mailing list)
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
technoweenie (Guest)
on 2005-11-24 00:26
(Received via mailing list)
On 11/23/05, Ben A. <removed_email_address@domain.invalid> 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/He...

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
This topic is locked and can not be replied to.