要容易搜索所有相關的模型屬性之前,這仍然問題問 :太陽黑子資料,匹配搜索相關模型屬性導致
剖面模型
has_one :match
searchable do
integer :id
string :country
string :state
string :city
end
匹配模式
belongs_to :profile
searchable do
integer :id
string :looking_for_education do
match.looking_for_education
end
integer :age_from
integer :age_to
end
Pr ofilesController#指數
def index
@search = Sunspot.search Profile do
with(:country, params[:country]) # this is a profile attribute
with(:state, params[:state]) # this is a profile attribute
with(:looking_for_education, "high school") # this should search *inside*
#the match attribute's,
#where **match** belongs_to
#**profile**
end
@profiles = @search.results
end
編輯#1
改寫了搜索塊像與第一個答案建議:looking_for_education做塊。仍未有未定義的方法`looking_for」爲#
新增整數ID來索引還是同樣的問題:(
self.match.looking_for_education,Match.looking_for_education和您的建議都會導致未定義的方法'looking_for_education'爲nil:NilClass。 – Rubytastic