简体   繁体   English

Ruby on Rails:错误的参数数量(3个为2)

[英]Ruby on Rails: wrong number of arguments (3 for 2)

For some reason I am getting an error on this method when I am trying to add a record. 出于某种原因,当我尝试添加记录时,我收到此方法的错误。 The specific error is wrong number of arguments (3 for 2) 特定错误是错误的参数数量(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

This is the request parms: 这是请求参数:

Request 请求

Parameters: 参数:

{"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"}

What am I missing? 我错过了什么?

Any help appreciated. 任何帮助赞赏。

至少在Geokit的 master中, (我假设您使用的是宝石)MultiGeocoder扩展了Geocodergeocode的方法签名只需要2个参数 ,一个address和可选的options哈希。

You have to give a location as the first parameter here, and options as the rest: 您必须在此处将位置作为第一个参数,并将选项作为其余参数:

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

Try to send it as a string, like this: 尝试将其作为字符串发送,如下所示:

MultiGeocoder.geocode("#{params[:street]}, #{params[:city]}, #{params[:state]}")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM