r = Radar.criteria
=> #<Mongoid::Criteria:0x00000104753d48 @selector={}, @options={}, @klass=Radar, @documents=[]>
r.map(&:title)
=> ["1", "2", "3", "4", "5", "6"]
r.active.around(Radius.new,current_location).newest.map(&:title)
=> ["6", "5", "4", "3", "2", "1"]
第1步
r.active.around(Radius.new,current_location).newest.paginate(:page => 1, :per_page => 3).map(&:title)
=> ["3", "2", "1"] ]
第2步
r.active.around(Radius.new,current_location).newest.paginate(:page => 2, :per_page => 3).map(&:title)
=>["3", "2", "1"]
在Step1中,分页应返回=&gt; [“6”,“5”,“4]
当我更新到most_commented范围时,一切正常。
r.active.around(Radius.new,current_location).most_commented.map(&:title)
=> ["1", "2", "3", "4", "5", "6"]
r.active.around(Radius.new,current_location).most_commented.paginate(:page =>1 ,:per_page => 3).map(&:title)
=> ["1", "2", "3"]
r.active.around(Radius.new,current_location).most_commented.paginate(:page =>2 ,:per_page => 3).map(&:title)
=> ["4", "5", "6"]
scope :most_commented, :order_by => [:comment_count,:desc]
scope :newest, :order_by => [:created_at,:desc]
def self.around(distance,location)
radius = distance.to_rad
near(:coords => location.coords + [radius])
end
ps:我总是在每个例子中使用新的r = Radar.criteria我为了简化而从输出中删除了
答案 0 :(得分:0)
我发现。附近的内容很好用于跳过
ruby-1.9.2-head&gt; r = Radar.criteria
ruby-1.9.2-head > r.active.near(:coords => ul.coords).newest.map(&:title)
=> ["6", "5", "4", "3", "2", "1"]
ruby-1.9.2-head > r.active.near(:coords => ul.coords).newest.skip(2).map(&:title)
=> []
ruby-1.9.2-head > r.active.newest.skip(2).map(&:title)
=> ["4", "3", "2", "1"]