Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
How Do i loop two tables in a rake task ROR

so am writing a system of which each user has an account and deposits. so my user model is:

    has_many :deposits

account model belongs_to :user deposit model belongs_to :user

In my rake task am trying to find and verify each deposit and once verified, the equivqlent is updated to the account.balance

  desc "Depost Verification per plans"
  task testest2: :environment do

    @users = User.all


    @users.each do |u|
      puts u.email

      u.accounts.each do |a|
      puts  a.first_name
      puts  a.balance
      end

      u.deposits.each do |d|
      puts  d.amount
      end


      @accounts = u.accounts.all
      @deposits = u.deposits.all

      @accounts.each do |b|
        puts b.first_name
      end
    print "Commands working here error begins on the next paragrah"
    print "how do i achieve this loop using the above parameters"

    @accounts.zip(@deposits).each do |account, d|
        if d.status?
        acct_bal = account.balance.to_f + d.amount.to_f
        account.update!(balance: acct_bal)
        puts account.user.username
    
        puts account.balance
        print "Deposit Added"
      else
        acct_bal = account.balance.to_f + 0.00
        account.update!(balance: acct_bal)
        puts account.user.username
        print "Deposit Unverifed"
      end
    end
    


    end


    print "command run .........."



  end

Bt somehow am getting this error

/Users/fortune/.gem/ruby/2.7.2/gems/json-1.8.6/lib/json/common.rb:155: warning: Using the last argument as keyword parameters is deprecated
daveskeen24@gmail.com
DayTon
0.0
DayTon
Commands working here error begins on the next paragrahrails aborted!
NoMethodError: undefined method `status?' for nil:NilClass
/Users/fortune/sites/current/dapps/dayton/lib/tasks/deposits.rake:77:in `block (4 levels) in <main>'
/Users/fortune/sites/current/dapps/dayton/lib/tasks/deposits.rake:76:in `each'
/Users/fortune/sites/current/dapps/dayton/lib/tasks/deposits.rake:76:in `block (3 levels) in <main>'

What Do I Do.....???????????????????

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You probably have less @deposits than @accounts so d is nil, thats the behaviour of zip https://apidock.com/ruby/Array/zip

If I think correctly what you need is to have a link in the database between deposits and accounts, then get every account and check all its related deposits.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!