Anton Jenkins
2009-Mar-19 10:03 UTC
Suggested amendment to nested model forms documentation
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-nil-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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Mike Gunderloy
2009-Mar-19 10:38 UTC
Re: Suggested amendment to nested model forms documentation
http://guides.rubyonrails.org/contribute.html has the low-down on getting on to the docrails project. Then you can fix the guides and documentation yourself. Since you''ve hit the issue and come up with the explanation, you''re probably the best one to do the work. Mike On Mar 19, 2009, at 5:03 AM, Anton Jenkins wrote:> > Would it be possible to amend the rails guides and the > documentation...--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Pascal Ehlert
2009-Mar-19 10:40 UTC
Re: Suggested amendment to nested model forms documentation
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" <anton@pixellatedvisions.com> 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Eloy Duran
2009-Mar-19 10:41 UTC
Re: Suggested amendment to nested model forms documentation
Hi Anton, Yes, this will definitely be addressed in a guide I''m working on. There''s also a ticket about adding a better fallback in the case you are using fields_for for a nil association: http://rails.lighthouseapp.com/projects/8994/tickets/2172-nested-model-forms-error-on-loading-data-from-one-to-one-associations-that-evaluate-to-nil Cheers, Eloy On Mar 19, 2009, at 11:03 AM, Anton Jenkins 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-nil-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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Pascal Ehlert
2009-Mar-19 10:46 UTC
Re: Suggested amendment to nested model forms documentation
How could I miss that ticket? Thanks, let''s continue the discussion there. Best, Pascal On 3/19/09 11:41 AM, "Eloy Duran" <eloy.de.enige@gmail.com> wrote:> > Hi Anton, > > Yes, this will definitely be addressed in a guide I''m working on. > > There''s also a ticket about adding a better fallback in the case you > are using fields_for for a nil association: > http://rails.lighthouseapp.com/projects/8994/tickets/2172-nested-model-forms-e > rror-on-loading-data-from-one-to-one-associations-that-evaluate-to-nil > > Cheers, > Eloy > > On Mar 19, 2009, at 11:03 AM, Anton Jenkins 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- >> nil-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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Anton Jenkins
2009-Mar-19 11:28 UTC
Re: Suggested amendment to nested model forms documentation
I should have known you guys would be on the case already ;o) In future I''ll make a point of searching the lighthouse tickets first. In the meantime I''ll follow Mike''s advice and try and put a note on the rails guides release notes to warn users of this potential pitfall. Cheers Anton On Mar 19, 10:41 am, Eloy Duran <eloy.de.en...@gmail.com> wrote:> Hi Anton, > > Yes, this will definitely be addressed in a guide I''m working on. > > There''s also a ticket about adding a better fallback in the case you > are using fields_for for a nil association:http://rails.lighthouseapp.com/projects/8994/tickets/2172-nested-mode... > > Cheers, > Eloy > > On Mar 19, 2009, at 11:03 AM, Anton Jenkins 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-fo... > > > 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Anton Jenkins
2009-Mar-19 16:30 UTC
Re: Suggested amendment to nested model forms documentation
I''ve added a short explanation to the Rails 2.3 release notes : http://github.com/lifo/docrails/commit/3d3a74f07fe192cddeb6084e15f16fa08c451499 On Mar 19, 10:38 am, Mike Gunderloy <larkw...@gmail.com> wrote:> http://guides.rubyonrails.org/contribute.htmlhas the low-down on > getting on to the docrails project. Then you can fix the guides and > documentation yourself. Since you''ve hit the issue and come up with > the explanation, you''re probably the best one to do the work. > > Mike > > On Mar 19, 2009, at 5:03 AM, Anton Jenkins wrote: > > > > > Would it be possible to amend the rails guides and the > > documentation...--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Manfred Stienstra
2009-Mar-19 16:33 UTC
Re: Suggested amendment to nested model forms documentation
On Mar 19, 2009, at 5:30 PM, Anton Jenkins wrote:> > I''ve added a short explanation to the Rails 2.3 release notes : > > http://github.com/lifo/docrails/commit/3d3a74f07fe192cddeb6084e15f16fa08c451499I don''t think it''s a good idea to encourage people to build models in their views. You should probably tell them to build the association in the controller. Manfred --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Anton Jenkins
2009-Mar-20 08:49 UTC
Re: Suggested amendment to nested model forms documentation
Well, either way my edit got pulled from the release notes as they want to keep those static. As for where the building is happening - I just copied the technique used in the complex forms examples as I assumed that was the reference implementation. You''re probably right and this should go in the controller really seeing as it''s manipulating models. On Mar 19, 4:33 pm, Manfred Stienstra <manf...@gmail.com> wrote:> On Mar 19, 2009, at 5:30 PM, Anton Jenkins wrote: > > > > > I''ve added a short explanation to the Rails 2.3 release notes : > > >http://github.com/lifo/docrails/commit/3d3a74f07fe192cddeb6084e15f16f... > > I don''t think it''s a good idea to encourage people to build models in > their views. You should probably tell them to build the association in > the controller. > > Manfred--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---