0

出于某种原因,当我尝试添加记录时,此方法出现错误。具体错误是参数数量错误(3 代表 2)

    def addrecord
        res=MultiGeocoder.geocode(params[:street], params[:city], params[:state])
        lat, lng = res.ll.split(",") 
        Bathroom.create(:name =>params[:name],
                        :bathroomtype =>params[:bathroomtype],
                        :street =>params[:street],
                        :city =>params[:city],
                        :state =>params[:state],
                        :country =>params[:country],
                        :postal =>params[:postal],
                        :lat => lat,
                        :lon => lng,
                        :access =>params[:access], 
                        :directions =>params[:directions],
                        :comment =>params[:comment],
                        :created => Time.now,
                        :source => 'Squat',
                        :avail =>params[:avail] )
                        respond_to do |format|
                          format.json   { render :nothing => true }                  

                        end

      end

    This is an example call...

> http:..../bathrooms/addrecord?name=Apple%20Store&bathroomtype=1&street=One%20Stockton%20St.&city=San%20Francisco&state=CA&country=United%20States&postal=94108&access=0&directions=&comment=&avail=0

这是请求参数:

要求

参数:

{"city"=>"San Francisco",
 "avail"=>"0",
 "access"=>"0",
 "bathroomtype"=>"1",
 "comment"=>"",
 "country"=>"United States",
 "directions"=>"",
 "name"=>"Apple Store",
 "street"=>"One Stockton St.",
 "postal"=>"94108",
 "state"=>"CA"}

我错过了什么?

任何帮助表示赞赏。

4

2 回答 2

1

至少master对于Geokit(我假设您正在使用的 gem)MultiGeocoderextends Geocoder,谁的方法签名geocode 只需要 2 个参数,一个address和可选的options哈希。

于 2012-11-01T22:12:22.997 回答
1

您必须在此处将位置作为第一个参数,并将选项作为其余参数:

MultiGeocoder.geocode(params[:street], params[:city], params[:state])

尝试将其作为字符串发送,如下所示:

MultiGeocoder.geocode("#{params[:street]}, #{params[:city]}, #{params[:state]}")
于 2012-11-01T22:13:27.350 回答