Hi, I've found that issue to be annoying as well, you either need to clutter your controller with build statements or do something like this:
<% f.fields_for :address, @project.address.find_or_initialize %>.. I don't like either of these solutions and would personally prefer the nested form helpers to initialize a new record transparently for the purposes of the form. I can create a ticket with patch if you like the idea. Cheers Pascal On 3/19/09 11:03 AM, "Anton Jenkins" <[email protected]> wrote: > > I've noticed a couple of people tripping up (myself included) on using > the new nested model forms across has_one relationships. Because > @parentModel.childModel returns nil (as opposed to [] for a has_many > relationship) it is not possible to assign attributes to a new child > model in a has_one relationship without running > @parentModel.build_childModel first. > > I've explained the exact error and the solution in more detail here : > > http://www.pixellatedvisions.com/2009/03/18/rails-2-3-nested-model-forms-and-n > il-new-record > > Would it be possible to amend the rails guides and the documentation > on the rails blog on nested model forms to clarify this extra step > which is required for has_one relationships? The documentation as it > stands gives the impression that has_many and has_one are > interchangeable without any modification to your nested form code. > Just a simple note on this extra build_ step could save users a lot of > head scratching. > > Cheers > > Anton > > P.S The complex_form_examples were invaluable in helping me track down > where I was going wrong in this instance. These are a great idea for > when you are having problems getting your own code to work and you > need a working example. Thank you to those responsible! > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" 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-core?hl=en -~----------~----~----~----~------~----~------~--~---
