I think I'm making life hard for myself.

Just browsed through the form_helper.rb code and found what was
happening.

     def object
        @object || @template_object.instance_variable_get("@#
{...@object_name}")
      rescue NameError
        # As @object_name may contain the nested syntax (item
[subobject]) we
        # need to fallback to nil.
        nil
     end

So when it's a nested object I get nil.

InstanceTag goes through a bunch of acrobatics in initialize
to get the actual object values.

Still doesn't give me any easy way to access the object of the
FormBuilder.

On Oct 15, 7:04 pm, "stuart.coyle" <[email protected]> wrote:
> I'm using the fields_for helper with accepts_nested_attributes_for
> The System model has_many children.
>
> If I do this in my haml template:
>
> -form_for @system do |s|
>     =s.text_field :name
>
>     -s.fields_for :children do |child_fields|
>             =child_fields.text_field :name
>
> all is fine. The fields_for iterates over all children and puts the
> correct data in the fields.
>
> But...what I want to do is access the child object in that loop.
> With normal fields_for I could do:
>             =child_fields.object.foo()
> within the loop, but that no longer works since child_fields.object is
> nil.
> How do I access the child object?
> Do I just have to revert to creating a separate iteration over the
> child objects?
--~--~---------~--~----~------------~-------~--~----~
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