From: "J. B. Rainsberger" Date: 2006-11-21T15:08:20+09:00 Subject: Re: Inserting multiple rows from array David Lelong wrote: > Hi, > > I have two sets of values: > > job.id = 1 and contact_ids = [4, 8] > > I want to be able to iterate over all of values in the contact_id array > and create database records consisting of a job_id and contact_id. > > So, in this example, the end result would be two new records that > contain: > > -------------------- > |job_id |contact_id| > -------------------- > | 1 | 4 | > -------------------- > | 1 | 8 | > -------------------- > > Any advice? contact_ids.map { |each| AssignedJob.new({:job_id => job.id, :contact_id => each}) }.each { |each| each.save! } This is ActiveRecord code, or pretty close to it. First, turn the data into row objects, then ask each one to save itself. I hope that helps. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca Your guide to software craftsmanship JUnit Recipes: Practical Methods for Programmer Testing 2005 Gordon Pask Award for contribution Agile Software Practice