堆
- 红宝石 => 1.9.2 头
- 导轨 => 3.0.1
- will_paginate => (3.0.pre2)
- 蒙戈 => (1.1.5)
- mongoid => (2.0.0.beta.20)
- 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 我从输出中删除了它以简化