简体   繁体   中英

How can I show Active Admin filters depending of controller params

I need to do something like this:

filter :name, if: proc { params[:foo] == 'bar' }

Or even better do something like this:

if params[:foo] == 'bar'
  filter :name
end

Probably it does not make any sense trying to access URL params outside a controller block. However to give you some context I have two index pages (like table and grid) and need to show some filters in the table one but not in the grid one. The way I can tell it's rendering one or the other is checking the as parameter.

Any ideas?

This is what I came up with. Not sure if this is the best way but it works.

before_filter :only => :index do
  @as = params[:as]
end

filter :name, if: proc { @as == 'grid' }

# This does not work
if @as == 'grid'
  filter :name
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM