Search code examples
jquerysqlruby-on-railsruby-on-rails-5grails-controller

Single chronological feed from multiple tables data with Rails 5


I have 2 tables Posts & Websites. I have a single feed where I want to display posts and websites together in chronological order.

How can I do that? Currently, I pull separately

Posts.all in posts_controller and
Websites.all in websites_controller

Thank you!

enter image description here


Solution

  • @feed = (@posts + @websites).sort_by {|a| a.created_at}.reverse
    

    this simple line solved it!