设置ActiveAdmin过滤器默认值 [英] Set ActiveAdmin filter default value
本文介绍了设置ActiveAdmin过滤器默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在ActiveAdmin中有一个用于布尔值的简单过滤器。看起来像这样
I have a simple filter in ActiveAdmin for boolean value. It looks like this
filter :invisible, as: :select
您可以选择 any, true或 false,并且效果很好。但是过滤器的默认值为 any,而我需要将其设置为 true。我该怎么做?谢谢。
You may choose "any", "true" or "false" and it works just fine. But the default value of the filter is "any", while I need to set it to "true". How can I do it? Thank you.
推荐答案
我找到了答案。您必须使用 before_filter
,就像操作
I've found an answer. You have to use before_filter
so it is as simple as
controller do
before_filter invisible: :index do
params[:q] = {invisible_eq: true} if params[:commit].blank?
end
end
这篇关于设置ActiveAdmin过滤器默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文