Set ActiveAdmin filter default value

跟風遠走 提交于 2019-12-12 04:46:41

问题


I have a simple filter in ActiveAdmin for boolean value. It looks like this

filter :invisible, as: :select

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.


回答1:


try some like this :

filter : invisible, as: :select, collection: [["Yes", true], ["No", false]]

This works fine for me.

Obviously you can edit the "Yes" - "No" string as you want.




回答2:


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


来源:https://stackoverflow.com/questions/24335297/set-activeadmin-filter-default-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!