良い解決策は見つかりませんでしたが、ここに方法があります。Active_adminのフィルターはmeta_searchによって実行されます。モデル内のmeta_searchによって自動的に生成された関数をオーバーライドして、目的の動作を取得できます。他のクエリとチェーンするためにリレーションを返す必要があるため、スコープを使用するのが最善の方法です。 / scopes、ここで述べられているように
モデル内:
:as =>:selectフィルターの場合、acitve_adminは_eqを使用します。ここで、ソースコードは次のとおりです。
scope :map_eq,
lambda{ |id|
if(id !='none')
where( :map_id=> id)
else
where( :map_id=> nil)
end
}
#re-define the search method:
search_method :map_eq, :type => :integer
ative_adminレジスタブロック内:
filter :map_id, :label => 'Assigned', :as => :select, :collection => [['none', 'none'], ['one', 1],['tow', 2]]
# not using :none=>nil because active_admin will igore your nil value so your self-defined scope will never get chained.
この助けを願っています。