Multiple Values in Form Field and Creating Multiple Records


#1

Hi,

I want to be able to have users enter one or more email addresses in a
field and have a database row created for each of those email addresses.

The contents of the database row would be:

created_on
job_id
user_id
email_address

Here is an example of my form output:

{“commit”=>“Send”, “email”=>{“created_on”=>“12-29-2006 @ 14:12 PM”,
“job_id”=>“1”, “user_id”=>“4”, “email_address”=>“removed_email_address@domain.invalid,
removed_email_address@domain.invalid, removed_email_address@domain.invalid”}}

I can easily get the values for created_on, job_id, and user_id, but how
do I iterate over the email addresses?

Thanks,

David


#2

Hi David,

David L. wrote:

I want to be able to have users enter one or more email addresses in a
field and have a database row created for each of those email addresses.

Here is an example of my form output:

“email_address”=>“removed_email_address@domain.invalid,
removed_email_address@domain.invalid, removed_email_address@domain.invalid”}}

how do I iterate over the email addresses?
Assuming your email address table was named something like ‘addresses’
you
could do something like…

params[:email_address].each(’,’) {|this_address|
address_to_add = Address.new
address_to_add.created_on = params[:created_on]
address_to_add.job_id = params[:job_id]
address_to_add.user_id = params[:user_id]
address_to_add.email_address = this_address
address_to_add.save
}

hth,
Bill