0

我正在使用thinking sphinx,带有sphinx_select 参数来创建一个动态字段,如下所示:

@subjects = Subject.search(sphinx_select: "*, petals < 1 or color = 2 as my_attribute")

有没有办法custom_attribute在搜索结果中访问?例如:

@subjects.each do |s|
    s.my_attribute
end

退货

undefined method `my_attribute' for #<Subject:0x007fb25cdcdb18>
4

1 回答 1

0

在思考的狮身人面像源中进行了一些挖掘并弄清楚了这一点。动态属性存储在一个match对象中,可以像这样访问它:

@subjects.each_with_match do |s, match|
    match[:attributes]["my_attribute"]
end
于 2012-10-02T02:49:59.340 回答