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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:51:20+00:00 2026-05-23T03:51:20+00:00

I want to create an activity feed from recent article and comments in my

  • 0

I want to create an activity feed from recent article and comments in my rails app. They are two different types of activerecord (their table structures are different).

Ideally I would be able to create a mixed array of articles and comments and then show them in reverse chronological order.

So, I can figure out how to get an array of both articles and comments and then merge them together and sort by created_at, but I’m pretty sure that won’t work as soon as I start using pagination as well.

Is there any way to create a scope like thing that will create a mixed array?

One of the other problems for me, is that it could be all articles and it could be all comments or some combination in between. So I can’t just say I’ll take the 15 last articles and the 15 last comments.

Any ideas on how to solve this?

  • 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-23T03:51:21+00:00Added an answer on May 23, 2026 at 3:51 am

    When I’ve done this before I’ve managed it by having a denormalised UserActivity model or similar with a belongs_to polymorphic association to an ActivitySource – which can be any of the types of content that you want to display (posts, comments, up votes, likes, whatever…).

    Then when any of the entities to be displayed are created, you have an Observer that fires and creates a row in the UserActivity table with a link to the record.

    Then to display the list, you just query on UserActivity ordering by created_at descending, and then navigate through the polymorphic activity_source association to get the content data. You’ll then need some smarts in your view templates to render comments and posts and whatever else differently though.

    E.g. something like…

    user_activity.rb:

    class UserActivity < ActiveRecord::Base
      belongs_to :activity_source, :polymorphic => true
    
      # awesomeness continues here...
    end
    

    comment.rb (post/whatever)

    class Comment < ActiveRecord::Base
      # comment awesomeness here...
    end
    

    activity_source_observer.rb

    class ActivitySourceObserver < ActiveRecord::Observer
    
      observe :comment, :post
    
      def after_create(activity_source)
        UserActivity.create!(
          :user => activity_source.user, 
          :activity_source_id => activity_source.id, 
          :activity_source_type => activity_source.class.to_s, 
          :created_at => activity_source.created_at, 
          :updated_at => activity_source.updated_at)
      end
    
      def before_destroy(activity_source)
        UserActivity.destroy_all(:activity_source_id => activity_source.id)
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an app that contains a Service S and an Activity
I want to create the activity which will load the images from Web by
I want to create my Rails application with MySQL, because I like it so
I've got an Android activity which grabs an RSS feed from a URL, and
I want to create a transparent Activity on top of another activity. How can
I want to create loading progress bar when my activity is starting. I have
I want to create checkbox in my preference Activity that allows user to toggle
i want to create a widget app that when added will start ConfigurationActivity which
I am trying to create an Activity class from a string and pass it
I want to create application with two Tabs, like follow: MainClass: private TabHost tabHost;

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.