I’m really struggling to figure out how to iterate through some data and then ‘do’ something before moving on to next record.
In the following array, I need to extract the ‘batch_id’ and use this variable in another action. My query looks like this:
data = item.line_items.map { |li| li.variant.product }
Output:
[#<Spree::Product id: 706676762, name: "60 Minute Internet Voucher", description: "Lorem ipsum dolor sit amet, consectetuer adipiscing...", available_on: "2012-02-12 18:06:08", deleted_at: nil, permalink: "60-minute-prepaid-wifi-internet-voucher", meta_description: "", meta_keywords: "", tax_category_id: 25484906, shipping_category_id: 727197547, created_at: "2012-02-12 18:06:08", updated_at: "2012-02-21 09:16:01", count_on_hand: 9999964, batch_id: 1, is_voucher: true>, #<Spree::Product id: 569012001, name: "Ruby Baseball Jersey", description: "Lorem ipsum dolor sit amet, consectetuer adipiscing...", available_on: "2012-02-12 18:06:08", deleted_at: nil, permalink: "ruby-baseball-jersey", meta_description: "", meta_keywords: "", tax_category_id: 25484906, shipping_category_id: nil, created_at: "2012-02-12 18:06:08", updated_at: "2012-02-20 22:04:04", count_on_hand: 1000, batch_id: 2990, is_voucher: false>]
I need to iterate through each record one by one, extracting the batch id for another query. Then move on to the next one. I thought something like this might do it but I can’t quite get my head around it:
1.upto(max_loop) do |i|
batch_id = xxxx
Spree.get("/api/v1/radcheck/spree_index?batch_id=#{batch_id}")
...
end
You probably just want: