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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:43:35+00:00 2026-05-20T00:43:35+00:00

I have a large data set that I want to clean up for the

  • 0

I have a large data set that I want to clean up for the user. The data set from the DB looks something like this:

ID | project_id | thread_id | action_type |description
 1 | 10         | 30        |  comment    | yada yada yada yada yada
 1 | 10         | 30        |  comment    | xxx
 1 | 10         | 30        |  comment    | yada 313133
 1 | 10         | 33        |  comment    | fdsdfsdfsdfsdfs
 1 | 10         | 33        |  comment    | yada yada yada yada yada
 1 | 10         |           | attachment  | fddgaasddsadasdsadsa
 1 | 10         |           | attachment  | xcvcvxcvxcvxxcvcvxxcv

Right now, when I output the above in my view its in the very same order as above, problem is it is very repetitive. For example, for project_id 10 & thread_id 30 you see:

10 - 30 - yada yada yada yada yada
10 - 30 - xxxxx
10 - 30 - yada yada yada yada yada

What I would like to learn how to do in ruby, is some how create an array and aggreate descriptions under a project_id and thread_id, so instead the output is:

10 - 30
 - yada yada yada yada yada
 - xxxxx
 - yada yada yada yada yada

Any advice on where to get started? This requirement is new for me so I would appreciate your thoughts on what you’re thinking the best way to solve this is.Hopefully this can be done in ruby and not sql, as the activity feed is likely going to grow in event types and complexity.

Thanks

  • 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-20T00:43:36+00:00Added an answer on May 20, 2026 at 12:43 am

    Use group_by http://apidock.com/rails/Enumerable/group_by in Ruby or right in SQL. In Ruby:

    sets = DataSet.all.group_by{ |data| [data.project_id, "-", data.thread_id].join(" ") }
    

    Then you’ll get Hash like that:

    { "10 - 30" => [#DataSet1, #DataSet2 ...], "10 - 33" => [#DataSet7, #DataSet11 ...]
    

    Which you can parse in view:

    <% sets.each do |range, datas| %>
      <p><%= range %>:</p>
      <% datas.each do |data| %>
        <p><%= data.description %></p>
      <% end %>
    <% end %>
    

    UPD for each_with_index

    <% sets.each_with_index do |datas, index| %>
      <p><%= datas[0] %>:</p>
      <% datas[1].each do |data| %>
        <p><%= data.description %></p>
        # some stuff with *last*
        <%= "This is the last one" if data == datas[1].last %> 
      <% end %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a costumer showing Notepad with a large set of data that looks
A newbie question from me, please. I have a large data set that I
I have a very large possible data set that I am trying to visualize
I have situation where a user can manipulate a large set of data (presented
I have large data set, which I want to query. The query does not
I have a large data set that is updated once a day. I am
Interpolating Large Datasets I have a large data set of about 0.5million records representing
I have a large set of data (a data cube of 250,000 X 1,000
I have a python module which generates large data files which I want to
I have a large non-map image that I want to allow people to view

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.