braintree - Rails 4 : Active record collection looping or iteration -


in rails customer controller there active record collection object:

1. @pay_invoices = invoice.where(customer_id: @pay_cus_id)

#<activerecord::relation [#<invoice id: 37, customer_id: 53, paid_amount: 960, devicemodel_id: 2, transaction_id: "6drv3s", created_at: "2016-01-04 05:29:03", updated_at: "2016-01-25 12:16:14">, #<invoice id: 70, customer_id: 53, paid_amount: 80, devicemodel_id: 2, transaction_id: "2mr93s", created_at: "2016-01-28 09:02:43", updated_at: "2016-01-28 09:02:43">]> 

also in controller using transaction_id: column value find out transaction details in braintree payment gateway using following braintree api call:

 @tid = @pay_invoices[0].transaction_id   @transaction = braintree::transaction.find(@tid) 

this works fine me, transaction details of first transaction_id: @pay_invoices collection can retrieved using code, want iterate through @pay_invoices collection , each time want store braintree transaction details collection, can display payment details fro each transaction in view.

how achieve ?

transaction_ids = invoice.where(customer_id: @pay_cus_id).pluck(:transaction_id) @transactions = [] transaction_ids.each |t_id|   @transactions << braintree::transaction.find(t_id) end 

though if there equivalent like

transaction_ids = invoice.where(customer_id: @pay_cus_id).pluck(:transaction_id) @transactions = braintree::transaction.where(transaction_id: transaction_ids) 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -