2014-06-07 1 views
0

상점, 차트 및 마지막 모델을 검색하고 싶습니다.
시간과 좌표에 대해서는 ID를 세션에 넣었습니다.
id를 다른 용도로 사용하고 싶습니다.
ID의 원본 모델을 식별 할 수있는 방법이 있습니까?태양 흑단 다중 모델 검색에서 모델을 식별하는 방법은 무엇입니까?

@searchs = Sunspot.search store, chart, last do |s| 
     s.fulltext params[:search] 
     s.with(:end_at).greater_than(Time.now) 
    end.results 
    ar=[] 
    @searchs.each do |a| 
     if a.coordinate_x.nil? || a.coordinate_y.nil? 
     next 
     end 
     ar << a.id 
    end 
    session[:stores_id] = ar 

답변

0

원본 모델을 식별하려면 더 많은 정보를 저장해야합니다. 결과를 반복 할 때 클래스 이름을 가져 와서 저장할 수 있습니다. 이 정보를 바탕으로 유형을 검사하는 소스 모델을 식별 할 수 있습니다.

@searchs = Sunspot.search store, chart, last do |s| 
    s.fulltext params[:search] 
    s.with(:end_at).greater_than(Time.now) 
end.results 
ar=[] 
@searchs.each do |a| 
    if a.coordinate_x.nil? || a.coordinate_y.nil? 
    next 
    end 
    # Store the type of the item and its id. 
    ar << {type: a.class.name, id: a.id} 
end 
session[:stores_id] = ar