Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用Rails3上的思考狮身人面像进行排序?_Ruby On Rails_Sorting_Sphinx - Fatal编程技术网

Ruby on rails 如何使用Rails3上的思考狮身人面像进行排序?

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对象是think Sphinx类的一个实例

 @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_是可排序的