From: Glen Holcomb Date: 2008-07-15T05:09:30+09:00 Subject: Re: how to loop through two arrays in parallel ------=_Part_61266_16749176.1216066430055 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, Jul 14, 2008 at 2:03 PM, Mitchell Gould wrote: > I have two arrays from a form. > > > params[:products] and params[:quantity] > > which are products[] and quantity[] > > I would like to extract the data from each item to get their name and > quantity. > > Is there a way in Ruby to do this? > > > for product in products[] and quantity in quantity[]? > -- > Posted via http://www.ruby-forum.com/. > > product_quantity = {} products.each_with_index do |product, index| product_quantity[product.to_sym] = quantity[index] end Not the prettiest but assuming the two arrays are one-to-one it should give you a hash with product names for keys and quantities as values. -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_61266_16749176.1216066430055--