以下结果集适用于will_paginate:
Members.all(:limit => 5).paginate(:page => params[:page])
Members.all(:conditions => ["member_no < 6"]).paginate(:page => params[:page])
Members.all.paginate(:page => params[:page])
以下内容不是:
Members.all(:conditions => ["member_no IN (?)", [1, 2, 3, 4, 5]]).paginate(:page => params[:page])
为什么第二个查询与paginate不兼容?谢谢!
答案 0 :(得分:0)
#paginate是在Array和ActiveRecord :: Base上可用的实例方法。你真的应该这样做:
Member.paginate(:page => params[:page], :limit => 5)
Member.paginate(:conditions => ["member_no < ?", 6], :page => params[:page])
Member.paginate(:page => params[:page])
Member.paginate(:conditions => {:member_no => (1..5)}, :page => params[:page])
当你打电话给#all然后#paginate时,你正在做的是要求所有成员(所有1,000,000个成员),然后丢弃99.999%,因为你只需要前10个至少可以说,这非常浪费。