2012-12-16 2 views
1

GeoKit에서 작동하도록 우편 번호 검색을하는 데 문제가 있습니다. 일부 오류로 인해 전체 앱이 다운되고 있습니다. 어떤 도움을 주시면 감사Ruby on Rails : GeoKit 우편 번호 검색?

ArgumentError in BathroomsController#zipcode 

wrong number of arguments (2 for 1) 

Rails.root: /Users/chance 1/source/rails_projects/squat 
Application Trace | Framework Trace | Full Trace 

app/controllers/bathrooms_controller.rb:44:in `geo_scope' 
app/controllers/bathrooms_controller.rb:44:in `zipcode' 

Request 

Parameters: 

{"zipcode"=>"47130", 
"format"=>"json"} 

Show session dump 

Show env dump 
Response 

Headers: 

:

def zipcode 
    zipcode = params[:zipcode] 
    @bathrooms = Bathroom.geo_scope(:all, :origin=>[zipcode], :within=>10) 
    respond_to do |format| 
     format.json { render :json => @bathrooms } 
     #format.json { render :json => {:bathrooms => @bathrooms} } 
     format.js { render :nothing => true } 
    end   
    end 




match '/bathrooms/zipcode', :controller => 'bathrooms', action =>"zipcode" 

이 내가 점점 오전 오류는 다음과 같습니다

이 내가 가진 것입니다.

+0

실제 오류를 넣을 수 있습니까? Rails 로그 (logs/development.log)에서 오류/스택 추적을 찾을 수 있습니다 –

+0

ActionController :: RoutingError ([GET] "/bathrooms/zipcode.json"과 일치하는 경로 없음) : –

+0

Rendered /Library/Ruby/Gems/1.8 /gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (2.5ms) –

답변

0

geo_scopeonly one argument : 해시입니다. 기호 (:all)와 해시 (:origin=>[zipcode], :within=>10)의 두 인수를 전달합니다. 다음 중 하나만 예상하면 두 개의 인수가 수신되어 오류가 발생합니다.

wrong number of arguments (2 for 1) 

해결 방법에는 두 가지가 있습니다. 당신이 모두 GeoKit을 잊지 대신 geocoder을 사용할 수,

Bathroom.geo_scope(:origin=>[zipcode], :within=>10).all 

또는 :

먼저, :all 기호를 제거하고 파인더 방법을 사용할 수 있습니다. (github)

# GeoKit 
@bathrooms = Bathroom.geo_scope(:origin=>[zipcode], :within=>10).all 

# geocoder 
@bathrooms = Bathroom.near(zipcode, 10) 
+0

GeoKit 제안을 시도했지만 현재이 오류가 발생합니다 : 47130 (배열)을 LatLng로 정규화 할 수 없습니다. . 우리는 그것을 배열, 문자열, Mappable 등으로 해석해 보았지만 주사위는 사용하지 않았습니다. 음? –

+0

하지만이 작업은 ... @bathrooms = Bathroom.geo_scope (: origin => params [: zipcode], : within => 10) .all –

+0

도움을 주셔서 감사합니다! –