Finding nearby members by distance

Distance is now configurable
Units framework is there but it's not working yet
This commit is contained in:
Cesy Avon
2013-04-23 10:13:21 -07:00
parent 6caf8e4160
commit cebd49271a
3 changed files with 29 additions and 3 deletions

View File

@@ -36,8 +36,21 @@ class MembersController < ApplicationController
else
@location = nil
end
@distance = 100
@nearby_members = @location ? Member.near(@location, @distance) : []
if !params[:distance].blank?
@distance = params[:distance]
else
@distance = 100
end
# This isn't actually working yet
if !params[:units].blank?
@units = params[:units]
else
@units = :mi
end
@nearby_members = @location ? Member.near(@location, @distance, :units => @units) : []
respond_to do |format|
format.html # nearby.html.haml
format.json { render json: @nearby_members }

View File

@@ -4,7 +4,10 @@
%p
= form_tag(nearby_members_path, :method => :get, :class => 'form-inline') do
= label_tag :location, "Find members near", :class => 'control-label'
= label_tag :distance, "Find members within", :class => 'control-label'
= text_field_tag :distance, @distance, :class => 'input-mini'
- #= select_tag :units, options_for_select(["miles" => :mi, "km" => :km], @units), :width => "2em", :class => 'input-mini'
= label_tag :location, "miles of", :class => 'control-label'
= text_field_tag :location, @location
= submit_tag "Search", :class => 'btn btn-primary'

View File

@@ -105,6 +105,16 @@ describe MembersController do
assigns(:nearby_members).should include @member_far
end
it "finds them by miles" #do
# get :nearby, { :distance => "350", :units => :mi, :location => [55.953252, -3.188267] }
# assigns(:nearby_members).should include @member_near
#end
it "doesn't find them by km" #do
# get :nearby, { :distance => "350", :units => :km, :location => [55.953252, -3.188267] }
# assigns(:nearby_members).should_not include @member_near
#end
end
context "when the user is logged in but hasn't set their location" do