Geokit will process all distance calculations using haversine in the database. He also works great with the hero and postgres. Highly recommend.
Geokit Gem
Rails Geokit Integration
all code taken from github
class Location < ActiveRecord::Base
acts_as_mappable :default_units => :miles,
:default_formula => :sphere,
:distance_field_name => :distance,
:lat_column_name => :lat,
:lng_column_name => :lng
end
Store.find :all, :bounds=>[sw_point,ne_point]
bounds=Bounds.from_point_and_radius(home,5)
stores=Store.find :all, :include=>[:reviews,:cities] :bounds=>bounds
stores.sort_by_distance_from(home)