Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

v2.3 nested attributes, forms_for, child_form.object is always nil

#2040

Hello,

I installed Rails 2.3.0 using "gem install rails --source http://gems.rubyonrails.com".

Then I duplicated the example in http://ryandaigle.com/articles/2..., only

a) using FudgeFormBuilder (http://github.com/JimNeath/fudge...

b) using ResourceController (http://jamesgolick.com/2007/10/1...

With this setup, if I access child_form.object in a partial (or within a forms_for block), like detailed on jamesgolick.com, it is nil, regardless of whether I do @foo.child.build before to create child models.

Is this a bug in Rails, or is this a missing feature in FudgeFormBuilder (if so: what would I have to change?) or does ResourceController interfere?

In general: do custom FormBuilders which inherit from ActionView::Helpers::FormBuilder need to actively support the nested attributes display?

Thank you!

Jens

(PS: I'd like to evaluate this problem in more detail using the "nested_attributes" branch in git://github.com/alloy/complex-form-examples.git which allegedly includes a vendored current Rails 2.3 but I can't get a working checkout. Probably a problem between me and git. :-( Maybe somebody can tell me how to get a complete checkout of the right branch, including submodules etc? Thanks!)

Reported by Jens · February 22nd, 2009 @ 01:06 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Eloy Duran
    Eloy Duran
    • State changed from new to invalid

    Unless the the custom form builder messes with fields_for, or other standard methods, it should just work. And I know others have in fact been using custom form builders.

    I have no experience with ResourceController; please ask for specifics about it on the available support options for it or contact the author, this is not the right place for it. The same applies to working with git, there are plenty of pages on the web which explain how to do this, or join a irc channel like #github.

    February 22nd, 2009 @ 04:49 PM

  2. Jens
    Jens

    Thanks for your reply.

    I did all that already - IRC, Github messages, mailing list searches, Git tutorials, manpages and so on. I have also been fighting git and Github for too long and just cannot get this to work. I'm problably missing something obvious.

    I guess the bug will just have to wait until somebody else finds it, or until somebody has two minutes to explain how to do this checkout from Github so I can track the problem down.

    I'm perfectly willing to help - otherwise I wouldn't have written this bug report. I'm just stuck.

    Jens

    February 22nd, 2009 @ 05:27 PM

  3. Eloy Duran
    Eloy Duran

    Then please let us know what it is that you were trying and how it failed, otherwise the question is just a bit too ambiguous :)

    February 22nd, 2009 @ 05:51 PM

  4. Jens
    Jens

    Hi,

    I think I might have found the problem, but it might not be related to nested attributes alone.

    action_view/helpers/form_helper.rb:form_for is defined as follows (taken from the Rails Github source):

    # ... case record_or_name_or_array when String, Symbol object_name = record_or_name_or_array when Array object = record_or_name_or_array.last object_name = ActionController::RecordIdentifier.singular_class_name(object) # ...

    This means that if you use

    form_for(:user, ...) do |f|

    you will not get an @object instance. But if you use

    form_for(@user, ...) do |f|

    you will get an @object instance.

    At least, changing all my forms like this fixed the apparent problem I had with the custom FormBuilder.

    Can you find out whether this is intentional and why? If it is not and can be changed so that @object is instantiated regardless of the parameter format, I will perform more tests using accepts_nested_parameters_for.

    Thanks!

    Jens

    February 24th, 2009 @ 09:04 AM

  5. Eloy Duran
    Eloy Duran

    Ah, I understand. I don't think that it should resolve the instance, I'd rather have the user specify the instance. I'd only use the symbol form when it's not a local resource, so when you're creating a form for an external resource. But you might want to double-check that on the mailing list.

    February 24th, 2009 @ 09:23 AM