If you need to do the combination in Ruby (and I don't think you do; read on), you could do something like this, using
# just extracting these 2 params for clarity
controller_ids = params[:controller_id]
zone_numbers = params[:zone_number]
# product will give you every id/number combo,
# which is then mapped to a Zone record's ID
zone_ids = controller_ids.product(zone_numbers).map do |controller_id, number|
However! I'd suggest less Ruby and more SQL for this.
# line-breaks are for clarity
zone_ids = Zone.where(
'controller_id IN (?) AND number IN (?)', controller_ids, zone_numbers
That should pluck just the
id values from the Zones table without loading entire records.
While you can generate an array that contains every combination of controller ID and zone number, you'd still (with your current code) do separate DB queries for each of those combinations. And doing SQL queries in a loop is a sure sign you should look for another approach altogether (namely doing more in the DB layer, if possible).