0

  1. 红宝石 => 1.9.2 头
  2. 导轨 => 3.0.1
  3. will_paginate => (3.0.pre2)
  4. 蒙戈 => (1.1.5)
  5. mongoid => (2.0.0.beta.20)
  6. mongoid_slug => (0.4.6)

安慰

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 分页应该返回 => ["6", "5", "4]

当我将 latest 更改为 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"]

conole 中使用的范围

 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:我总是在每个示例中使用 new r=Radar.criteria 我从输出中删除了它以简化

4

1 回答 1

0

我发现 .near 与 skip 配合得很好

ruby-1.9.2-head > r = Radar.criteria

一切正常

ruby-1.9.2-head > r.active.near(:coords => ul.coords).newest.map(&:title)
=> ["6", "5", "4", "3", "2", "1"] 

相同的查询,但带有 .skip

ruby-1.9.2-head > r.active.near(:coords => ul.coords).newest.skip(2).map(&:title)
=> [] 

第一个使用 .skip 但没有 .near 的查询

ruby-1.9.2-head > r.active.newest.skip(2).map(&:title)
=> ["4", "3", "2", "1"] 
于 2011-01-04T09:39:32.503 回答