我正在使用这个要点在我的 Rails 应用程序中构建自动完成功能。
我在Shoe
模型属性中保存记录,如下所示
"nike air, nike steam,nike softy ,nike strength" #comma separated words
我的控制器代码如下
def shoes
shoes_list = []
shoes = Shoe.all
shoes.each do |shoe|
shoes_list << shoe.model.split(',')
end unless shoes.blank?
if params[:term]
like = "%".concat(params[:term].concat("%"))
# shoes = Shoe.where("model like ?", like)
# **How i make like query to "shoes_list" same like above commented line?**
else
shoes = Shoe.all
end
list = shoes.map { |u| Hash[id: u.id, label: u.model, model: u.model] }
render json: list
end
如何以 json 格式呈现它?