Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin select filter collection

I am trying to create a select category filter in ActiveAdmin(1.0.0pre4) with Rails 4. Every company has different categories. How can I create a filter collection which is based on the current_user's company?

filter :by_category,
        as: :select,
        collection: proc { Category.by_company(current_company) }

This results in an undefined method 'map' for #<Proc:0x007fccc3b29340>

If I remove the surrounding proc than I got the following error when I start the server:

undefined local variable or method 'current_company' for #<ActiveAdmin::ResourceDSL:0x007fb8a8c332b0> (NameError)

Is it possible to do this with ActiveAdmin 1.0.0pre4?

like image 717
kriskova Avatar asked Sep 16 '26 14:09

kriskova


1 Answers

Can you get the current_company from the current_user ? ie current_user.company

If so,

filter :by_category,
       as: :select,
       collection: proc { Category.by_company(current_user.company) },
       label: 'Category'
like image 120
Joey Avatar answered Sep 19 '26 08:09

Joey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!