Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Rails 中,我经常这样做:
Model.last(5).first
这将检索最后一个元素-5。
有内置的方法吗?
更常见的方式是 offset()
Model.offset(5).last
编辑(对于懒惰的人):
1.8.7 :001 > User.first.id => 1 1.8.7 :002 > User.last.id => 143455 1.8.7 :003 > User.offset(5).last.id => 143450