ruby-on-railsactiveadmin

Set ActiveAdmin filter default value


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.


Solution

  • I've found an answer. You have to use before_filter so it is as simple as

    controller do
      before_filter only: :index do
        params[:q] = {invisible_eq: true} if params[:commit].blank?
      end
    end