OK, Ive built a status feed for this site Im making which shows a user the recently added artwork of a user they are following. I have another feed that shows recently added comments by the followed user, which will soon be changed to comments added to the current user’s submitted work.
Anyway, I was wondering how to go about merging the two arrays into the same feed. So that way the feed will display both arrays, in order of created by.
Im thinking that in my model (where my feed is defined, see below), I would call the two queries, then add them together, then sort by created_at.
And in the view I would loop through the array, and use an if/else statement to correctly display the activity.
How would I go about actually merging and sorting the arrays?
edit – I should point out that my feed is defined in the my user model as
def feed
Image.followed_by(self.id)
Comment.followed_by(self.id)
end
You could add the two arrays together and then sort by created_at like this:
(array1 + array2).sort_by(&:created_at)