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

The Archive Base Latest Questions

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

I am working in rails 2.. I have a doubt. In my application ,

  • 0

I am working in rails 2.. I have a doubt.

In my application , i have 3 models like

Blog, Wiki , Media

I am trying to create an array like @final with all the blogs , wikis, medias posted under my application .

I have tried with

@blogs = Blog.all
@wikis = Wiki.all
@medias = Media.all

@final = []
@final << @blogs << @wikis << @medias

The above final array has 3 arrays in it..

But i am expecting to keep final array with the objects returned from 3 models

How to do so ??
PLease give suggestions

EDIT

I thing i tried is

 @final = []
 @blogs = Blog.all
 @wikis = Wiki.all
 @medias = Media.all
 @final = @blogs + @wikis + @medias

This is performing exactly what i need .. But its just listing all the blogs , medias and wikis. How to list all the entities based on the creation date of the particular object

  • 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-23T21:20:12+00:00Added an answer on May 23, 2026 at 9:20 pm

    You’re using the wrong operator, you want this:

    @final = @blogs + @wikis + @medias
    

    The << operator for an Array:

    Pushes the given object on to the end of this array.

    whereas the + operator:

    Returns a new array built by concatenating the two arrays together to produce a third array.

    You could also use flatten if you were really attached to << for some reason:

    @final = (@final << @blogs << @wikis << @medias).flatten
    

    but that would be a bit pointless. As noted by powerMicha, you need to start the << chain off with @final (or some temporary array) if you don’t want to modify any of the @blogs, @wikis, or @medias arrays.

    As far as sorting them goes, you could use sort_by!:

    @final.sort_by(&:created_at)
    

    That assumes that you have the usual created_at method on the objects.

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

Sidebar

Related Questions

I am working on a rails application (I have some experience with rails). But,
I'm working on a Rails application where I have some a set of two
I am thinking of working on a Rails application that uses PostgreSQL. I have
Background Currently, I am working on a Rails application. I have different products that
I am working with Rails fixtures for testing my rails application. It is all
I have a working Rails application on version 2.3.5 - I am using many
I have a library that I'm trying to get working with rails 3 (specifically
I have created a blog application using Ruby on Rails and have just added
I have a working rails 3.1 application that uses the mercury wysiwyg editor, however
I have a rails app I am working on that allows users to create

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.