Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6116045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:09:40+00:00 2026-05-23T15:09:40+00:00

I have a users object that I’m exposing through the simple call: @users =

  • 0

I have a users object that I’m exposing through the simple call:

@users = User.all

I also have some more expensive queries I’m doing where I’m using custom SQL to generate the results.

@comment_counts = User.received_comment_counts

This call and others like it will return objects with one element per user in my list ordered by id.

In my view I’d like to loop through the users and the comment_counts object at the same time. Eg:

for user, comment_count in @users, @comment_counts do
end

I can’t figure out how to do this. I also can’t seem to figure out how to get an individual record from the @comment_counts result without running it through @comment_counts.each

Isn’t there some way to build an iterator for each of these lits objects, dump them into a while loop and step the iterator individually on each pass of the loop? Also, if you can answer this where can I go to learn about stepping through lists in rails.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:09:40+00:00Added an answer on May 23, 2026 at 3:09 pm

    Something like this should work for you:

    @users.zip(@comment_counts).each do |user, comments_count|
      # Do something
    end
    

    I’ve never come across manual manipulation of iterators in Ruby, not to say that it can’t be done. Code like that would likely be messy and so I would likely favor more elegant solutions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simplified example: I have an object that models a user. Users have a first
I have a function that loads a user object from a web service asynchronously.
I have a NSTimer object that I need to invalidate if a user taps
I have the following code that loads a user's Active Directory DirectoryEntry object from
I have a form that is bind to an object, and when the user
I have a display object that displays a list of Users and provides a
I have an object that handles the logging in of users. This object has
I have an existing Perl script that uses the FTP object to send a
I have an AJAX application that downloads a JSON object and uses the data
I have a web application that uses the CDO Message object to email reports.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.