簡體   English   中英

Ruby on Rails中的Geokit,測距儀,如何按最近到最遠排序?

[英]Geokit in Ruby on Rails, distance finder, how to sort by nearest to farthest?

我正在使用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升序列出。 我希望它從最遠到最遠排序。 我該怎么辦?

謝謝。

我相信您正在尋找的是:

   def self.find_this_within(origin, within)
    if origin.geocoded?
      find(:all, :origin => origin, :within => within, :order => 'distance asc')
    else
      []
    end
  end

或說文檔: http//geokit.rubyforge.org/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM