简体   繁体   English

使用Rails 5从多个表数据按时间顺序提供

[英]Single chronological feed from multiple tables data with Rails 5

I have 2 tables Posts & Websites. 我有2个表格帖子和网站。 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 Posts.all在posts_controller和
Websites.all in websites_controller Websites.all在sites_controller中

Thank you! 谢谢!

在此处输入图片说明

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

这条简单的线解决了它!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM