Ruby on rails 如何使用Rails3上的思考狮身人面像进行排序?
我正在尝试使用传递给控制器的参数完成一个简单的排序。我在搜索和思考斯芬克斯网站上跟踪,遇到了以下错误。我做错了什么 下面的@places对象是think Sphinx类的一个实例Ruby on rails 如何使用Rails3上的思考狮身人面像进行排序?,ruby-on-rails,sorting,sphinx,Ruby On Rails,Sorting,Sphinx,我正在尝试使用传递给控制器的参数完成一个简单的排序。我在搜索和思考斯芬克斯网站上跟踪,遇到了以下错误。我做错了什么 下面的@places对象是think Sphinx类的一个实例 @places = Place.search(params[:q], :order => :created_at) ThinkingSphinx::SphinxError (index place_core: sort-by attribute 'created_at' not found): 您需要添加要
@places = Place.search(params[:q], :order => :created_at)
ThinkingSphinx::SphinxError (index place_core: sort-by attribute 'created_at' not found):
您需要添加要搜索的字段。然后,要按字段排序,需要在模型中将其标记为可排序,或者需要在define_index方法中添加一个属性作为 对于您的模型,如下所示:
class Place < ActiveRecord::Base
# ...
define_index do
# fields
indexes subject, :sortable => true
indexes content
indexes author.name, :as => :author, :sortable => true
# attributes
has created_at
end
# ...
end
classplacetrue
索引内容
索引author.name,:as=>:author,:sortable=>true
#属性
在
结束
# ...
结束
在该示例中,subject、author和created_是可排序的