如何先显示preserve_default_filters!并在自定义过滤器之后

How to show first preserve_default_filters! and after custom filter

我的代码中有这个:

  preserve_default_filters!
  filter :oculto,
    as: :check_boxes,
    collection: [['Oculto', true], ['visible', false]],
    label: 'Mostrar'

我想先显示默认过滤器,然后再显示我的自定义过滤器,但我不知道如何。

我附上了我的索引页示例,它是如何显示的以及我想要它的方式

这不受开箱即用的支持,但通过阅读我发现 https://github.com/activeadmin/activeadmin/blob/1290efa1fc7984badebe774f108d886a1e82624c/lib/active_admin/filters/resource_extension.rb#L93..L97 的代码,这导致我将上面的 preserve_default_filters! 替换为:

config.send(:default_filters).each { |f| filter f }
filter :oculto ...

这会采用默认过滤器并将它们插入到您的过滤器之前。提交拉取请求将其添加到 lib/activeadmin/filters/dsl.rb:

可能会很有趣
def default_filters
  config.send(:default_filters).each { |f| filter f }
end

然后您就可以通过以下方式注册资源:

default_filters
filter :oculto ...