Search code examples
ruby-on-railsruby-on-rails-3scopewill-paginatefeed

Paginate data from two models into one newsfeed: Ruby on Rails 3 // Will_paginate


I'd like to make a newsfeed for the homepage of a site i'm playing around with. There are two models: Articles, and Posts. If I wanted just one in the newsfeed it would be easy:

 @newsfeed_items = Article.paginate(:page => params[:page])

But I would like for the two to be both paginated into the same feed, in reverse chronological order. The default scope for the article and post model are already in that order.

How do I get the articles and posts to be combined in to the newsfeed as such?

Thanks!

EDIT: What about using SQL in the users model?

Just wondering: maybe would it be possible define in User.rb:

 def feed
    #some sql like (SELECT * FROM articles....)
 end

Would this work at all?


Solution

  • for those interested, please check this question: Creating a "feed" from multiple rails models, efficiently?

    Here, Victor Piousbox provides a good, efficient solution.