RESTfully creating 2 models at once

Hi there,

I have a system with users who have groups of contacts (ie. other
users). I’m trying to be as RESTful as possible, working on edge rails,
and using map.resources for as much as possible.

The problem is that I have a form for the user to add a new contact.
They can choose to put the contact in one of their existing groups, or
they can create a new group at the same time.

Pretty standard stuff, except I can’t figure out the way to do it
RESTfully. It’s one submission from one form. If they’re using an
existing group, it’s fine, it’s just creating a contact, and it makes
sense to POST to the CREATE action in the CONTACTS_controller. However
if I’m also creating a group, right now I have it set up to create the
group in the contacts_controller, though I feel like it should be in
it’s own groups_controller

Anybody have any suggestions, or encountered a similar issue?

Thanks!

Cameron

On 11/21/06, Cameron B. [email protected] wrote:

Pretty standard stuff, except I can’t figure out the way to do it
RESTfully. It’s one submission from one form. If they’re using an
existing group, it’s fine, it’s just creating a contact, and it makes
sense to POST to the CREATE action in the CONTACTS_controller. However
if I’m also creating a group, right now I have it set up to create the
group in the contacts_controller, though I feel like it should be in
it’s own groups_controller

Anybody have any suggestions, or encountered a similar issue?

You can just POST a contact and have the contact create also create a
group on-the-fly if necessary (i.e., if specified group doesn’t
exist), which sounds like what you’re doing. I don’t see anything
wrong with that. You can of course also provide a RESTful
groups_controller to allow for POSTING of groups per-se, and there’s
nothing wrong with that.


Bosko M. [email protected]
http://www.crowdedweb.com/