2013-11-27 20 views
0

資產具有狀態和編號列表。我的目標是使用sunspot添加可搜索性並對狀態和編號進行排序。在我的資產模型我有:製作一個字段可供太陽黑子進行訂購

class Asset < ActiveRecord::Base 
    ⋮ 
    searchable do 
    text :statuses do 
     statuses.map(&:name) 
    end 
    ⋮ 

然後在我的資產控制器我有:

Asset.search do 
    ⋮ 
    order_by :statuses, :desc 
end 

當我嘗試運行它,我得到一個錯誤:

Sunspot::UnrecognizedFieldError in SearchController#assets 

No field configured for Asset with name 'statuses' 

中的定義資產模型的searchable部分正在配置字段,對嗎?

我也嘗試將join添加到狀態列表中以將其轉換爲字符串,但這並沒有幫助。

回答

1

我非常確定,太陽黑子不能按您索引爲文本的字段排序。但你可以用字符串來訂購。

相反的:

text :statuses do 
    statuses.map(&:name) 
end 

嘗試:

string :statuses do 
    statuses.map(&:name) 
end