How would you be able to find on two different models and sort as in one array by the created_at column

So, for example ... Suppose I have a message model and a news model, which are essentially the same (structure wise)
columns - * name
* content
* createdat
* updatedat

The client requested to display both news and messages on one page, alternating and sorted by created_at date ...
Does anyone know how I will do something like this?

+3
source share
2 answers
(Post.all + News.all).sort_by(&:created_at)
+2
source

, cwninja , .

raw SQL, .

0

Source: https://habr.com/ru/post/1721571/


All Articles