想要轻松搜索所有关联的模型属性之前问过这个问题仍然存在:
轮廓模型
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
ProfilesController#Index
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 do 块重写可搜索块,就像在第一个答案建议中一样。仍然以未定义的方法“looking_for”失败#
在索引中添加了整数 :id 仍然是相同的问题 :(