Best way to implement Contact - Multiple emails structure

Hello to everybody.

I am trying to accomplish the following and would like your opinion on which is the best way to do it.

My DB has contacts which may have from 0 to infinite email addresses. I want to give users the ability to add/delete/edit email addresses when they update the parent contact record and just add/remove emails when creating the contact record. (Pretty much what gmail does in contacts without the auto saving 905

addemail.png
)

I created two tables/models/controllers/views, one for Contacts and one for Emails. The Emails table has a ContactID field in order to support the 1:MANY relationship needed.

What I am currently doing, but don’t like much is:

[list=1]

[*]In contact/update view display an ajax link that calls email/create action and appends the result to a div (i use the create action here because the email create view contains fields such as email label, is primary email radio button etc.)

[*]If the "Add email" button is pressed again, email/create action is called again and tabular data may be collected

[*]In contact/update action I perform validation for all email models the user posts and show errors

[*]If the form contains no errors I delete all previous emails found for this contact and store the ones submitted

[/list]

The drawback of the above semi-solution is that the entire code for validating tabular input needs to be rewritten in Contact/create action + I want to support multiple phone numbers for contact records… :blink:

Confident that there is a better way to do this, I thank you in advance for sharing it with me.

Any ideas on this issue, anyone?