Topic: Many Members at one Address

Greetings;

To make it easy to save on postage, I am building our Rails-based membership database so that there is a one-to-many relationship between Addresses and Members, so that many members living at one Address would only get one piece of mail.

For most membership categories there is a one-to-one relationship between Address and Member, but for "group" (family, organization) Members there is a one to many relationship between Address and Member.

I am adapting the Member _form and controller generated as part of the scaffold script, but am running into a snag as I try to accomodate a shifting number of "other members".

How would you handle this situation?

thanks for any ideas

-sporb

Re: Many Members at one Address

What "snag" are you running into? Can you be more specific?

Railscasts - Free Ruby on Rails Screencasts

Re: Many Members at one Address

Hi;

Here's my example workflow:
Staff needs to enter the data from a completed (paper) membership form; this form has one main member name and three other (family) member names at a given address.

So, here's what I could present to take this input:

Scenario 1: I could have an input field for the "main member" name and a fixed number of input fields for "other members at this address", let's say 5 of them.

Staff would then enter data into four of these six fields and the controller would create members for those four members (Associating them all with the given address), and ignore the remaining 2 empty fields.

I suppose these fields could be named member1, member2, member3, etc and the controller could use those field names when creating new Member objects.

Scenario 2: I could present a drop-down box that prompts the Staff person to indicate "how many  other members at this address" which would then us javascript to draw the required  number of input fields, which could be numbered as above.

I guess my issue is that this all seems a little kludgy. I'm still trying to "think the Rails way" as much as possible... as I said, any feedback would be appreciated.

thanks!

-sporb

Re: Many Members at one Address

Hey sponb,
I had to do something like this but instead of members I was tracking children at addresses.

This is what I did.

For your family & organizations memberships, create the address first then add members to that address. Your application might look something like this:

<add address>

Address 1     <add member>
# of members
Name 1
Name 2

Address 2    <add member>
# of members
Name 1
Name 2


I passed the address_id to the kids form in the controller like

Re: Many Members at one Address

You may be interested in this tutorial on creating variable number of models in one form. Basically this will allow you to dynamically create members while you are creating a given address. Sounds like this is what you're trying to do?

Railscasts - Free Ruby on Rails Screencasts

Re: Many Members at one Address

Thanks for the help! This is exactly what I am trying to do.

The link, however, points to something in the API; I did find some articles on this subject at the following urls, though:

Section 1:  http://railsforum.com/viewtopic.php?id=717
Section 2:  http://railsforum.com/viewtopic.php?pid=5238
Section 3:  http://railsforum.com/viewtopic.php?id=1065

-sporb