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

  • Home
  • SEARCH
  • 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 8635303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:56:29+00:00 2026-06-12T09:56:29+00:00

I have two tables named users and billing . In users I have the

  • 0

I have two tables named users and billing. In users I have the usual information, while in billing (contains user_id field for reference) I have things like balances by month for each user. My problem comes from when I want to list the monthly balances. On the monthly balances page I want to display the user(s)’s name, balanace for the month and other misc information, however the billing table only holds the user’s id.

At first i tried

@mondetail = Billings.find_by_date(201204) #April's billing period
@customer = Users.find_by_id(mondetail.user_id)

which works fine for one user but how should I go about this when I want to display the information from both tables with multiple users? Or would it just be best for me to add a user_name field to the billing table?

  • 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-06-12T09:56:30+00:00Added an answer on June 12, 2026 at 9:56 am

    You don’t need find user’s info in controller. You can get it from Billing model. (Strange that models are plural)

    # controller
    @mondetail = Billings.includes(:user).find_by_date(201204)
    
    
    # view
    <% @mondetail.each |mondetail| %>
     <%= mondetail.user.name %><br />
     <%= number_to_currency mondetail.balance %>
    <% end %>
    

    It’s will work and without includes but you should avoid N + 1 queries problem

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

Sidebar

Related Questions

I have two tables. One named status like this... user_id | status --------+----------- 1
I have two tables. One named status like this... user_id | status --------+----------- 1
I have two tables named users and contacts . I would like to delete
I have two tables: Users: ID, first_name, last_name Networks: user_id, friend_id, status I want
i have two tables in my database : Users : contain user information UserTypes
I have two tables in my database, and I would like to retrieve information
I have MySQL database with two tables: users and items. They look like this:
I have two tables users table: id|name user_relationships id | user_id | friend_id and
I have two tables. One contains information on hotels, added to my website by
I have two tables. One contains information on hotels, added to my website by

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.