我正在使用Geokit。我的模型中有以下内容:
# Distance-based finder method
# Usage:
# - find_this_within(Shop.first, 10)
def self.find_this_within(origin, within)
if origin.geocoded?
find(:all, :origin => origin, :within => within )
else
[]
end
end
然后在我的控制器中:
@shops = s.paginate(:page => params[:page], :per_page => 20)
目前输出以ID升序列出。我希望它从最近到最远排序。我该怎么办?
感谢。
答案 0 :(得分:0)
我相信你要找的是:
def self.find_this_within(origin, within)
if origin.geocoded?
find(:all, :origin => origin, :within => within, :order => 'distance asc')
else
[]
end
end