如何使用searchkick gem在rails中映射多个属性
这是我的代码工作正常但我想添加多个属性,即last_name,city等。
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
你可以做:
Doctor.search(params[:query], autocomplete: true, limit: 10).map{|doctor| doctor.slice(:first_name, :last_name, :city, :country) }