0

I'm using Geokit. I have the following in my model:

  # 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

Then in my controller:

@shops = s.paginate(:page => params[:page], :per_page => 20)

Currently the output is listed in ID ascending. I want it to sort from nearest to furthest. What should I do?

Thanks.

Victor
  • 13,010
  • 18
  • 83
  • 146

1 Answers1

0

I believe what you are looking for is:

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

Or so say the Docs: http://geokit.rubyforge.org/

Zach Inglis
  • 1,242
  • 1
  • 14
  • 28