Johnny Rottenweed
Johnny Rottenweed

Reputation: 337

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)

    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.

Upvotes: 0

Views: 567

Answers (2)

Mauricio Pasquier Juan
Mauricio Pasquier Juan

Reputation: 2365

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]}")

Upvotes: 1

deefour
deefour

Reputation: 35350

At least in master for Geokit, (the gem I'm assuming you're using), MultiGeocoder extends Geocoder, who's method signature for geocode only expects 2 arguments, an address and optional options hash.

Upvotes: 1

Related Questions