My search form looks for an object in the database based on the address field. Everything works fine if i search only for the city name, for example Milan, but the search breaks if a select the complete google maps address suggested via maps Api. For example "metropolitan city of Milan" or some address "Via Paolo Sarpi, Milano, Metropolitan City of Milan, Italy" I got:
ArgumentError in PagesController#search
Unsupported argument type: 0 (Integer)
app/controllers/pages_controller.rb:14:in `search'
Started GET "/search?search=Via+Paolo+Sarpi%2C+Milano%2C+Metropolitan+City+of+Milan%2C+Italy&start_date=&end_date=&commit=Search" for ::1 at 2020-07-16 15:13:19 +0200
Processing by PagesController#search as HTML
Parameters: {"search"=>"Via Paolo Sarpi, Milano, Metropolitan City of Milan, Italy", "start_date"=>"", "end_date"=>"", "commit"=>"Search"}
Completed 500 Internal Server Error in 243ms (ActiveRecord: 0.0ms | Allocations: 1931)
Im using geocoder, ransack gem and geocomplete script.
schema.rb
t.string "location"
home
<%= form_tag search_path, method: :get do %>
<%= text_field_tag :search, params[:search], placeholder: "Where are you going?", class: "form-control" , id:"autolocation"%>
...
$(function () {
jQuery("#autolocation").geocomplete();
});
page_controller
class PagesController < ApplicationController
...
def search
if params[:search].present? && params[:search].strip !=""
session[:loc_search] = params[:search]
end
....
if session[:loc_search] && session[:loc_search] != ""
*@cars_address = Car.where(active: true).near(session[:loc_search], 5, order:* 'distance')
else
@cars_address = Car.where(active: true).all
end
.....