mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-04-14 03:47:59 -04:00
Finding nearby members by distance
Distance is now configurable Units framework is there but it's not working yet
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user