0

我的搜索表单根据地址字段在数据库中查找对象。如果我只搜索城市名称(例如米兰),一切正常,但如果选择通过 maps Api 建议的完整谷歌地图地址,则搜索会中断。例如“米兰大都会”或某个地址“Via Paolo Sarpi, Milano, Metropolitan City of Milan, Italy” 我得到了:

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)

我正在使用geocoder、 ransack gem 和geocomplete脚本。

架构.rb

t.string "location"

<%= 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
.....
4

0 回答 0