I was wondering how best to handle forms where I''m presenting a model and some of its "children", i.e. a Person with multiple IM contacts or something. I had a look at some of the source in HighriseHQ, figuring hey, if anybody knew how to do it it was David himself, and I noticed something interesting. The models are roughly like this: Person: has_one :contact_data ContactData: belongs_to: person has_many :instant_messengers has_many :phone_numbers InstantMessenger: belongs_to :contact_data If you look at the form when editing a person, you see stuff like this: <select id="person_contact_data__phone_numbers__location" name="person[contact_data][phone_numbers][][location]"><option value="Work" selected="selected">Work</option> and even more nested, this: <input id="instant_messenger_2406533_id" name="person[contact_data] [instant_messengers][][id]" type="hidden" value="2406533" /> <input class="autofocus" id="person_contact_data__instant_messengers__address" name="person[contact_data][instant_messengers][][address]" size="30" type="text" value="anna-8NRYcHeZzJdxCLhjislNzA@public.gmane.org" /> So as you can see, it looks like this can basically get slurped up by the controller and probably in one fell swoop everything is either updated or created. So my question is, how did the Gods of Rails pull this off? It looks like functionality that would find a happy place in the framework, but I don''t think I''ve seen it anywhere. Thanks, -elan --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
carlos.okada-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-20 21:52 UTC
Re: Forms with nesting/composite models
Hi Elan Do you know Railscasts? (http://railscasts.com/) Ryan, in the last 3 episodes (complex forms), shows how to do this kind of stuf. Okada. On Oct 20, 4:48 am, elan <elan.feing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I was wondering how best to handle forms where I''m presenting a model > and some of its "children", i.e. a Person with multiple IM contacts or > something. I had a look at some of the source in HighriseHQ, figuring > hey, if anybody knew how to do it it was David himself, and I noticed > something interesting. The models are roughly like this: > > Person: > has_one :contact_data > > ContactData: > belongs_to: person > has_many :instant_messengers > has_many :phone_numbers > > InstantMessenger: > belongs_to :contact_data > > If you look at the form when editing a person, you see stuff like > this: > > <select id="person_contact_data__phone_numbers__location" > name="person[contact_data][phone_numbers][][location]"><option > value="Work" selected="selected">Work</option> > > and even more nested, this: > > <input id="instant_messenger_2406533_id" name="person[contact_data] > [instant_messengers][][id]" type="hidden" value="2406533" /> > <input class="autofocus" > id="person_contact_data__instant_messengers__address" > name="person[contact_data][instant_messengers][][address]" size="30" > type="text" value="a...-8NRYcHeZzJdxCLhjislNzA@public.gmane.org" /> > > So as you can see, it looks like this can basically get slurped up by > the controller and probably in one fell swoop everything is either > updated or created. > > So my question is, how did the Gods of Rails pull this off? It looks > like functionality that would find a happy place in the framework, but > I don''t think I''ve seen it anywhere. > > Thanks, > > -elan--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Carlos, Thanks a lot for the tip, that''s exactly what I was looking for! -elan --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---