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 6024459
In Process

The Archive Base Latest Questions

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

I am solving a question, how to print for an item in one table

  • 0

I am solving a question, how to print for an item in one table appropriately items from second table.

In ‘TabA’ I have id:
1
2
3
4

In ‘TabB’ I have tab_a_id:
2
3
3
3
3
3
4

Specifically, my situation looks this:

as_controller

@info_a = TabA.all(:joins => :bs, :conditions => [“city = ?”, 0])

view

  <% for info in @a %>
    <tr>
      <td><%= info.id %></td>
      <td><%= info.email %></td>
      <td><%= HERE I WOULD LIKE TO PRINT COUNT ITEMS FROM TabB ('bs' controller, 'b' model) %></td>
    </tr>
  <% end %>

And I am trying to found, how to print e.g. for item with ID number 3 from ‘TabA’ the count of lines in ‘TabB’ (in TabB is 5 times the value 3).

Thanks in advance!

EDIT: solution – info.tabb.size

  • 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-23T04:09:30+00:00Added an answer on May 23, 2026 at 4:09 am

    Why don’t you set up an association between A and B models? This way, you could do this: a.b.count.

    The problem of your approach is that you request all the rows from the DB, Rails wraps them with AR objects, put them into array and than calculate the size of it. count on the other hand tells the DB to count the results and returns only one number so it is much more faster.

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

Sidebar

Related Questions

i have a table and the content of it is all from data base
I am solving the question about downloading a large amounts of picture from the
this question is from Codechef.com [if anyone is still solving this question dont look
I have given up on solving this one on my own, and any help
This question is more about guidance than actually solving my problem: I need to
I am solving the problem in the interview question about LinkedList. question is... Write
This is related to my previous question I'm solving UVA's Edit Step Ladders and
<hyperbole> Whoever answers this question can claim credit for solving the world's most challenging
After solving my last problem with CSS position a new one came up. Live
While solving exercises from the K&R C book, I stumbled upon the exercise 2.1.

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.