Frage

Ich habe @products Sammlung und ich möchte zusammenführen image_ids zu einem einzelnen Array.Hier ist die Ausgabe von @products.map(&:image_ids):

@products.map(&:image_ids)
=> [[1654, 1655, 1656],
 [1649, 1650, 1652, 1653],
 [1625],
 [1624],
 [1623],
 [1622],
 [1621],
 [1620],
 [1619],
 [1618]]
War es hilfreich?

Lösung

Gehen Sie wie folgt vor flat_map :

@products.flat_map(&:image_ids)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top