如果搜索项太长,则搜索函数出错不支持的参数类型:0(整数)
Search function error if search term is too long Unsupported argument type: 0 (Integer)
我的搜索表单效果很好,除非搜索词太长,我不知道为什么会这样。
我正在使用 ransack 进行搜索。
例如,我得到了这个:
Started GET "/search?search=Via+Per+Trognano%2C+Riozzo%2C+Metropolitan+City+of+Milan%2C+Italy&start_date=&end_date=&commit=Search" for ::1 at 2020-07-21 17:43:25 +0200
Processing by PagesController#search as HTML
Parameters: {"search"=>"Via Per Trognano, Riozzo, Metropolitan City of Milan, Italy", "start_date"=>"", "end_date"=>"", "commit"=>"Search"}
Completed 500 Internal Server Error in 228ms (ActiveRecord: 0.0ms | Allocations: 2027)
ArgumentError (Unsupported argument type: 0 (Integer)):
app/controllers/pages_controller.rb:14:in `search'
正如你想象的那样,我的表格正在查找汽车地址
汽车table:
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"%>
<%= submit_tag "Search", class: "btn btn-normal btn-block" %>
<% end %>
pages_controller
class PagesController < ApplicationController
def home
@cars = Car.where(active: true).limit(3)
end
def search
if params[:search].present? && params[:search].strip !=""
session[:loc_search] = params[:search]
end
arrResult = Array.new
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
@search = @cars_address.ransack(params[:q])
@cars = @search.result
@arrCars = @cars.to_a
search.js
$('#car_listing').html('<%= j render partial: "cars/cars_list", locals: {cars: @arrCars} %>')
initialize(<%= raw @arrCars.to_json %>)
来自https://github.com/activerecord-hackery/ransack#usage
The default param key for search params is now :q, instead of :search.
This is primarily to shorten query strings, though advanced queries
(below) will still run afoul of URL length limits in most browsers and
require a switch to HTTP POST requests. This key is configurable.
你需要切换到post方法
我的搜索表单效果很好,除非搜索词太长,我不知道为什么会这样。 我正在使用 ransack 进行搜索。 例如,我得到了这个:
Started GET "/search?search=Via+Per+Trognano%2C+Riozzo%2C+Metropolitan+City+of+Milan%2C+Italy&start_date=&end_date=&commit=Search" for ::1 at 2020-07-21 17:43:25 +0200
Processing by PagesController#search as HTML
Parameters: {"search"=>"Via Per Trognano, Riozzo, Metropolitan City of Milan, Italy", "start_date"=>"", "end_date"=>"", "commit"=>"Search"}
Completed 500 Internal Server Error in 228ms (ActiveRecord: 0.0ms | Allocations: 2027)
ArgumentError (Unsupported argument type: 0 (Integer)):
app/controllers/pages_controller.rb:14:in `search'
正如你想象的那样,我的表格正在查找汽车地址
汽车table:
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"%>
<%= submit_tag "Search", class: "btn btn-normal btn-block" %>
<% end %>
pages_controller
class PagesController < ApplicationController
def home
@cars = Car.where(active: true).limit(3)
end
def search
if params[:search].present? && params[:search].strip !=""
session[:loc_search] = params[:search]
end
arrResult = Array.new
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
@search = @cars_address.ransack(params[:q])
@cars = @search.result
@arrCars = @cars.to_a
search.js
$('#car_listing').html('<%= j render partial: "cars/cars_list", locals: {cars: @arrCars} %>')
initialize(<%= raw @arrCars.to_json %>)
来自https://github.com/activerecord-hackery/ransack#usage
The default param key for search params is now :q, instead of :search. This is primarily to shorten query strings, though advanced queries (below) will still run afoul of URL length limits in most browsers and require a switch to HTTP POST requests. This key is configurable.
你需要切换到post方法