开发者

select from 2 tables and order them in rails

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜