저는 Rails 애플리케이션을 사용하고 있습니다.이 애플리케이션은 팀 구성원을 추적하고 상태 업데이트를 통해 업데이트 된 상태를 추적하는 데 사용됩니다. 핑 '. 트위터는이 상태를 '트윗'이라고 부릅니다.최근 상태 업데이트 위치를 쿼리하여 특정 위치의 사용자를 찾습니다.
사원 (: FIRST_NAME : LAST_NAME)
핑 (: 날짜 : 상태 : 위도, 경도)
직원 모델 :
애플리케이션의 요점이있다
class Employee < ActiveRecord::Base
has_many :pings
has_one :ping, :order => "created_at DESC" # Returns the lastest Ping (employee.ping)
end
핑 모델 :
class Ping < ActiveRecord::Base
belongs_to :employee
acts_as_mappable :default_units => :miles,
:default_formula => :sphere,
:distance_field_name => :distance,
:lat_column_name => :latitude,
:lng_column_name => :longitude
end
모든 직원의 최신 핑을 현재 위치로 쿼리해야합니다. 문제는 어떻게 해야할지 모르겠다.
현재 위치의 모든 핑을 검색하면 직원에게 속한 여러 핑을 얻을 수 있습니다. 그 다음 각 ping.id과 employee.ping.id을 비교하여 그 중 하나가 직원의 최신 핑인지 확인해야합니다.
지리적 위치 정보가 Ping 개체에 있으므로 직원을 검색 할 수 없습니다. 그리고 내가 관심있는 유일한 핑은 최신 것들입니다. 어떤 의견에 대한
핑 컨트롤러
def location
pings = Ping.geo_scope(:within => params[:distance], :origin => [params[:latitude], params[:longitude]])
render :json => pings, :include => :employee, :only => [:id, :first_name, :last_name, :status, :longitude, :latitude]
# this returns all Pings that were ever created in this location.
end
감사 도와주세요!
감사합니다. Robin에게 도움을 요청합니다.
employees = Employee.all
current_pings = []
employees.each do |employee|
current_pings << employee.ping.id
end
pings = Ping.geo_scope(:within => params[:distance], :origin => [params[:latitude], params[:longitude]]).find_all_by_id(current_pings)
render :json => pings, :include => :employee, :only => [:id, :first_name, :last_name, :status, :longitude, :latitude, :created_at]