Re: Arbitrary sized collections

Shad Reynolds
Fri, 28 Oct 2005 23:50:21 -0000

Try this:

>          <% for feed in @feeds %>
>             <%= text_field ''feed'',
''url'' %>
>          <% end %>

@feed is referencing the instance variable :feed.

You want to create a variable local to the loop (feed).  Then,
reference that variable as just "feed" (which will contain each of the
values in sucsession).

Shad


On 10/28/05, Peter T. Brown
<peter-MTMYhAWfEVW8IPqWsmCfhg@public.gmane.org>
wrote:
> I have a list of URL''s I need to associate with a single Account
instance.
> In my form, the number of URL''s passed in is between 1 and 10. I
do not see
> how to handle this common situation...
>
> Having constructed the Feed model objects that hold the URL and are
> associated with the Account model I''ve tried:
>
>          <% for @feed in @feeds %>
>             <%= text_field ''feed[]'',
''url'' %>
>          <% end %>
>
> However this simply causes params(:feed) to equal the last item in the
> list... Since each of these Feed objects is constructed new, none of them
> have id''s. I''ve tried associated an incrementing index
doing something like:
> <%= text_field "feed[#{i}]", ''url'' %> but
I get the error: "`@feed[0]'' is
> not allowed as an instance variable name"
>
>
> What should I do?
>
> Thank You
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--