【发布时间】:2012-03-17 17:32:20
【问题描述】:
我想添加一个带有类别的 jquery 自动完成功能。 该请求将使用 Thinking Sphinx 搜索多个模型(论坛主题、新闻、用户...)
所以在控制器中,我认为它会是这样的
def autocomplete
@news = Actu.search(params[:term]).map {|g| {:label => g.title, :category => "Actualités", :id => g.id}}
@topics = Topic.search(params[:term]).map {|g| {:label => g.title, :category => "Topics", :id => g.id}}
@anotherModel = ...
respond_to do |format|
format.js { render :json => @news+@topics+@anotherModel }
end
end
这行得通,但是您如何看待这些做法?
【问题讨论】:
标签: ruby-on-rails postgresql sphinx thinking-sphinx