使用:限
在查询中,我会第一个N个记录。什么是拿到最后的N条记录的最简单的方法?
With :limit
in query, I will get first N records. What is the easiest way to get last N records?
像这样的活动记录查询我想你想要什么会让你('东西'是型号名称):
An active record query like this I think would get you what you want ('Something' is the model name):
Something.find(:all, :order => "id desc", :limit => 5).reverse
修改:正如评论指出,另一种方式:
edit: As noted in the comments, another way:
result = Something.find(:all, :order => "id desc", :limit => 5)
while !result.empty?
puts result.pop
end