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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:11:56+00:00 2026-06-09T20:11:56+00:00

I have two different kinds of conversations, started and joined. I want to render

  • 0

I have two different kinds of conversations, started and joined. I want to render them together in the same stream from newest on top to oldest on bottom. That is, I want them to be intermixed so that the newest conversation is on top regardless of whether it was started by the user or joined by the user (i.e. started by another user).

From my controller:

def conversations
  @user = current_user
  @joined_conversations = @user.received_meeting_requests.paginate(page: params[:page], :conditions => ['state = ?', 'replied'])
    @started_conversations = @user.sent_meeting_requests.paginate(page: params[:page], :conditions => ['state = ?', 'replied'])
end

In my view, I am rendering like this:

<ol class="meetings">
  <%= render @started_conversations %>
  <%= render @joined_conversations %>
</ol>
  <%= will_paginate @started_conversations %>
  <%= will_paginate @joined_conversations %>
<% end %>

So even the oldest started conversation will be above the newest joined conversation. How to I render these two objects so that they are intermixed, i.e. the newest started OR joined conversation will always be on top? 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-06-09T20:11:57+00:00Added an answer on June 9, 2026 at 8:11 pm

    Well, there are a few ways to actually go about it, but what you need is to have both kinds of conversations in one collection.

    Now, you could just take both your existing collections, put them together (using the Array union operator ‘|’), and resort them:

    def conversations
      @user = current_user
      @joined_conversations = @user.received_meeting_requests.paginate(page: params[:page], :conditions => ['state = ?', 'replied'])
      @started_conversations = @user.sent_meeting_requests.paginate(page: params[:page], :conditions => ['state = ?', 'replied'])
      @conversations = (@joined_conversations | @started_conversations).sort_by{|c| c.created_at}
    end
    

    However, since this sort of filtering and sorting is what databases are really for, I think you would do better to collect all the conversations that are relevant in one query. I’d like to tell you what that query is, but there’s no way to say without knowing about what your models/tables are, how they’re associated, what it means for a user to have joined or started a conversation, and for that matter what version of Rails and what database you’re using, since it will look quite a bit different in Rails 3.x vs 2.x.

    In either case, you’ll end up with one collection called @conversations, and should be able to simply render that.

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

Sidebar

Related Questions

I have two different buttons on my page. I want them both to be
I have two lists of two different kinds of objects representing data rows from
Is this possible to have two (or more) different kinds of cells to be
I have two different libGL libraries on the same Ubuntu 11.04 machine. One library
I have two different arrays, one with strings and another with ints. I want
I have two different-sized monitors, connected together using (I believe) TwinView. I tried System.out.println(Toolkit.getDefaultToolkit().getScreenSize());
I have two different tables from which I need to pull data blogs which
I have two different kinds of objects: Ride and Location . A Ride has
I have a database where I store two different kinds of data. One table
I have two different kinds of objects that I'd like to live under the

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.