我想使用带有可选参数的搜索(Thinking Sphinx)。
在我的控制器中,我有 3 个参数:
params[:model_id], params[:engine_id], params[:city_id]
控制器
def search
@search = Car.search :conditions => {
:model_id => params[:model_id],
:engine_id => params[:engine_id],
:city_id => params[:city_id]
}
end
模型
define_index do
indexes model_id
indexes city_id
indexes area_id
indexes engine_id
indexes mileage
end
当其中一个参数为 nil 时,我收到错误消息:
提取的源代码(第 4 行附近):
1: Result:
2: %br
3: %br
4: = render :partial => "search_item", :collection => @search, :as => :item
index car_core: syntax error, unexpected TOK_FIELDLIMIT near ' @engine_id @city_id'
UPD1:
我的表格
= form_tag search_adverts_path, :method => :get, :id => 'admin_quick_filter' do
%label
= t('form.mileage')
= text_field_tag :min_mileage, params[:min_mileage]
= text_field_tag :max_mileage, params[:max_mileage]
%br
= select_tag :model_id, options_for_select(Model.all.collect{|c| [c.name, c.id]} , params[:model_id]), :include_blank => true
%br
= select_tag :engine_id, options_for_select(Engine.all.collect{|c| [c.name, c.id]} , params[:engine_id]), :include_blank => true
%br
= select_tag :city_id, options_for_select(City.all.collect{|c| [c.name, c.id]} , params[:city_id]), :include_blank => true
%br
%br
= submit_tag t('form.search')
= render "search_result"