2014-01-12 15 views
0

这里是我的代码工作正常,但我想添加多个属性,即姓氏,城市等我如何在轨多重属性映射与searchkick宝石

def autocomplete 
    render json: Doctor.search(params[:query], autocomplete: true, limit: 10).map(&:first_name) 
end 

我希望下面的解释我的问题,你可能得到了我的观点,我可以使用下面的代码。

def autocomplete 
    render json: Doctor.search(params[:query], autocomplete: true, limit: 10).map(&:first_name, :last_name, :city, :country) 
end 
+0

这里是你的答案:http://stackoverflow.com/questions/28643262/searchkick-autocomplete-with-multiple-attributes/28643845#28643845 –

回答

1

你可以这样做:

Doctor.search(params[:query], autocomplete: true, limit: 10).map{|doctor| doctor.slice(:first_name, :last_name, :city, :country) } 
+0

这会导致自动完成下拉/建议显示“未定义”。 – iajnr