为什么这个分页计数器总是显示记录总数?
我有一个用户模型和图像模型,并且有 has_many 关系。 我在 images 表中有 18 条记录。现在的情况是:
@images = @user.images.paginate(:page => params[:page],:per_page=> 12)
p @images.count //output is always 18
图像数量为 18,
第一页总是 18,第二页又是 18。为什么会这样?第一页应为 12,第二页应为 6。
PS:只显示12条和6条记录,但计数器不正确。我只想获取该页面上的记录数。基本上最后一页(考虑按 id DESC 排序)计数器的范围为 1-12,我对该计数器感兴趣。
I have a user model and image model and having has_many relationships.
I have 18 records in images table. Now thing is:
@images = @user.images.paginate(:page => params[:page],:per_page=> 12)
p @images.count //output is always 18
Number of images is 18, always
For first page is 18 then for second page is again 18. Why is it so? It should be 12 for first page and then 6 for second page.
PS: It showing only 12 and 6 records but counter is not proper. I want to get number of records on that page only. Basically for last page (considering order by id DESC) counter my vary from 1-12 and I am interested in that counter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
长度返回什么?计数将访问数据库,
试试这个?我认为与分页一起使用效果会更好
What does length return? Count is going to hit the db,
Try this instead? I think it will work better with paginate