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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:40:21+00:00 2026-06-14T02:40:21+00:00

I have one instance variable with two records. id item_with_detail_id quantity 100 205 3

  • 0

I have one instance variable with two records.

           id   item_with_detail_id  quantity

           100       205                3


           101       205                5

Now, i want the result as follows using Active record group_by .

           100       205                8

i tried with

@bill_details=@bill_details.group_by{|bd| bd.item_with_detail_id}.values.map(&:first)

but its not working. Please help me to achieve the result.

  • 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-14T02:40:22+00:00Added an answer on June 14, 2026 at 2:40 am

    Finally i solved this problem. As follows

    In the controller =>

    @bill_details = @bill_details.group_by{|bd| bd.item_with_detail_id}.values
    

    it will give the following result

     #[[#<BillDetail id: 100, item_with_detail_id: 205, quantity: 3, #<BillDetail id:101, item_with_detail_id: 205, quantity: 5]]
    

    And in the view page:

    <% for bd in @bill_details%>
      <%quantity=0%>
      <%for bill_detail in  bd%>
      <%quantity+=bill_detail.quantity%>
      <%end%>
      <%bd=bd.first%>
    <%end%>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one static Semaphore instance. Semaphore semaphore = new Semaphore(1); Now I have
I have two instances of VS2010 running on same machine.One VS instance has a
i have a problem with boost condition, i have these two instance variable within
Dozer's documentation states that you should only have one instance of DozerBeanMapper running in
I have a program that only allows one instance of itself to run. I
I have 2 instance in windows azure. I am finding that only one instance
I have a property an NSArray property called toolbarButtons that in one instance (when
I'm adding HTML controls dynamically using java script. For instance, I have one button
I have only one class with many instances. Every instance is observer of couple
We have a weblogic server 10.0 instance which has a cluster with one managed

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.