2014-07-25 2 views
0

ActiveAdmin에서 다형성 연관을위한 필터를 포함하고 싶습니다.이 경우에는 enterable이라고합니다.다형 필터 컬렉션 : 2 테이블의 레코드

컬렉션을 지정해야하지만, 분명히 레코드가 다형성 연결의 여러 모델에서 왔기 때문에 여러 테이블의 레코드를 결합하는 방법을 잘 모르겠습니다. 이것은 분명히 부정확하지만 당신이하고자하는 것을 얻게됩니다.

filter :enterable, collection: [Award.all,Challenge.all], label: "Award/Challenge" 

어떤 아이디어라도 감사합니다.

답변

1

activeadmin < 1.0.0의 경우 https://github.com/activerecord-hackery/meta_search#multi-level-associations을 살펴보십시오. 이 절의 맨 아래에 다형성 연관을 처리하는 방법이 설명되어 있습니다. ActiveAdmin을> = 1.0.0를 들어

,이 SO에 대한 how to do this using ransack

ActiveAdmin.register Entry do 
    # For activeadmin < 1.0.0 , which uses meta_search 
    filter :enterable_award_type_title_or_enterable_challenge_type_title 

    # For activeadmin >= 1.0.0 , which uses ransack 
    filter :enterable_of_Award_type_title_or_enterable_of_Challenge_type_title 

    # A more programmatic approach to building this long name would be: 
    filter ([Award, Challenge].collect do |enterable| 
    "enterable_of_#{enterable.to_s}_type_title" 
    end.join("_or_")).to_sym 
end 
+0

감사에 의문을 참조 - 내가 추가 한 search_method 등 내 모델'Entry'하지만 내가 갖는'정의되지 않은 메서드 'search_method'에 for # '내가 잘못 가고있는 곳은 어디입니까? – Daniel

+0

답변을 완전히 업데이트했습니다. Activeadmin> = 1.0.0을 사용하고 있다고 생각합니다. 원래 응답은 이전 버전을 대상으로했습니다. –

+0

도와 주셔서 감사합니다. 그러나 filter : enterable_of_Award_type_title_or_enterable_of_Challenge_type_title (제목은 두 모델간에 공유됩니다) 필터는 나타나지 않으며 프로그램 버전에서는이 오류가 발생합니다 :'undefined method 'to_sym for # '('column_name'을': title'으로 바꾼 것) – Daniel