Reputation: 299
I want to use the value of the inner each
loop in the outer loop to pass it as an argument.
namespace :office do
desc "send reminder emails"
task send_reminder: :environment do
Office.all.each do |office|
office.issues.where("issues.amount > 0").each do |issue|
issue.billings.where("billings.date < ?", Message.last.date).order(:date).last # I will get billing_ids here which I want to pass as arguments in the outer loop.
end
ReminderWorker.perform_async(billing_ids)
end
end
end
How should I do this?
Upvotes: 1
Views: 125
Reputation: 1333
Try this:
Office.all.each do |office|
billing_ids=[] #initialize array
office.issues.where("issues.amount > 0").each do |issue|
billing_ids << issue.billings.where("billings.date < ?", Message.last.date).order(:date).last.id #add id to array
end
ReminderWorker.perform_async(billing_ids)
end
Upvotes: 1