2
votes

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?

1

1 Answers

2
votes

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) }