Marnen,
I do need fields_for, I am getting at data 2 levels deep in
associations (main table + association + association) and I need to
update the contents of the associations.
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:
<%= @my_object.my_collection[my_index].my_attribute %>
In any case, I found a line of code "hidden" in the documentation that
gave me a clue to find what I needed:
<% if project_fields.object.active? %>
As it turns out you can access the object that 'fields_for' is using
by just using method 'object' on the block object ("fieds_for_object"
in the sample below):
<% form_for :my_object, @my_object, :url => { :action => "my_action" }
do |form| %>
<% form.fields_for :my_collection do |fields_for_object| %>
<%= fields_for_object.object.my_attribute %> # <<< This is
what I was looking for
Thanks for the insight, though.
On Jan 9, 7:00 pm, Marnen Laibow-Koser <[email protected]> wrote:
> pepe wrote:
> > Sorry, there was a typo: <% from.fields_for :my_collection do |
> > fields_for_object| %> should have been <%
> > form.fields_for :my_collection do |fields_for_object| %>. Also, after
> > thinking about it, what I am really looking for is access to the
> > collection object being processed, not just one of it's attributes.
>
> Then why don't you just call methods on @my_object.my_collection ? It
> sounds like you don't need fields_for.
>
>
>
> > Any help would be much appreciated.
>
> > Thank you.
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> [email protected]
> --
> Posted viahttp://www.ruby-forum.com/.
--
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.