2012-10-02 68 views
0

我使用思維獅身人面像,與sphinx_select參數創建一個充滿活力的領域,像這樣:如何訪問搜索結果中的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> 

回答

0

的確在思考獅身人面像源了一些挖掘,想通了這一點。動態屬性存儲在一個match對象中,該對象可以這樣訪問:

@subjects.each_with_match do |s, match| 
    match[:attributes]["my_attribute"] 
end