On Sat, Jan 9, 2010 at 9:19 PM, pepe <[email protected]> wrote:
> I am just learning how to use 'fields_for' so forgive me if I sound
> like I don't know what I'm talking about.
>
> My understanding is that 'fields_for' will iterate through the
> collection, hence working with one element/object of the collection in
> each iteration. If I need an attribute from the element/object at each
> iteration, how would I know which element to access with
> @my_object.my_collection? I don't even know if there is an index I can
> use to get to the element I need as in @my_object.my_collection
> [my_index], hence allowing me to do something like:

No fields_for doesn't do any iteration. It's used for setting up a
scope for one or more form fields for a different object than the one
which scopes an outer form_for

>From the doc:

<% form_for @person, :url => { :action => "update" } do |person_form| %>
    First name: <%= person_form.text_field :first_name %>
    Last name : <%= person_form.text_field :last_name %>

    <% fields_for :person do |permission_fields| %>
       Admin?: <%= permission_fields.check_box :admin %>
    <% end %>
 <% end %>

So just like form_for doesn't do any iteration, neither does fields_for.

Since you haven't told us any more about what you want to do, I don't
know how to help any further.

-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to