Forms with nesting/composite models

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:

Work

and even more nested, this:


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

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.

Hey Carlos,

Thanks a lot for the tip, that’s exactly what I was looking for!

-elan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs