David Lelong
2006-Dec-29 18:31 UTC
Multiple Values in Form Field and Creating Multiple Records
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"=>"email-WNbSnoOWcWBBDgjK7y7TUQ@public.gmane.org,
email-dL8jOpOjefRBDgjK7y7TUQ@public.gmane.org,
email-msFaK4W69elBDgjK7y7TUQ@public.gmane.org"}}
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Bill Walton
2006-Dec-29 19:04 UTC
Re: Multiple Values in Form Field and Creating Multiple Records
Hi David, David Lelong 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"=>"email-WNbSnoOWcWBBDgjK7y7TUQ@public.gmane.org, > email-dL8jOpOjefRBDgjK7y7TUQ@public.gmane.org, email-msFaK4W69elBDgjK7y7TUQ@public.gmane.org"}} > > 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---