开发者

select from 2 tables and order them in rails

开发者 https://www.devze.com 2023-02-03 02:23 出处:网络
i want to selec开发者_如何学Got some rows from different tables and then i want to order them. how can i merge these results and order them according to their created_at values?

i want to selec开发者_如何学Got some rows from different tables and then i want to order them. how can i merge these results and order them according to their created_at values?

@books = Book.all
@notebooks = Notebook.all

@booksandnotebooks = ????


@booksandnotebooks = (@books + @notebooks).sort_by(&:created_at)

Isn't ruby lovely :)

0

精彩评论

暂无评论...
验证码 换一张
取 消