ActiveAdmin - Using areas with filters

In my ActiveAdmin model, I have a custom area to display deleted records and several filters to search for records by specific columns.

Using filters individually or in collaboration works as expected.

Using scope is working as expected.

The problem is that using the scope apparently overrides all the filters and after selecting the scope any added filter does nothing.

Does anyone have any ideas? I want to be able to show a specific area, and then still be able to filter the results within that area.

ActiveAdmin.register Example do scope :deleted do |example| Example.only_deleted end scope :all do |example| Example.with_deleted end filter :title filter :description index do column :title column :description end end 

[update]

Here is the solution I went with. I set the with_deleted scope to the model and included a filter on the side to show / hide deleted results. Not ideal, as initially deleted results are also shown, but at least all filters can be used together.

  ActiveAdmin.register Example.with_deleted do filter :title filter :description filter :deleted, :as => :select, :collection => {:true => nil, :false => false } index do column :title column :description end end 
+6
source share
2 answers

Instead of creating a scope, create another filter that will select records by criteria based on whether the examples are deleted or all. And apply as many filters as you want.

Or in the filter, when calculating the selector on which you will run the filter, perform the scope accordingly, and then set the filter conditions on this selector.

0
source

By default, ActiveAdmin wants applications to display only the symbolic name of the method. When you define scope in this way, they can be tied to the scope already provided by the filters, and they work together seamlessly.

So your error explicitly calls Model#class_method instead of providing :symbolized_class_method_name (with the implied owner of the current model).

Filters and scopes will work together if you replace this code:

 scope :all do |example| Example.with_deleted end scope :deleted do |example| Example.only_deleted end 

Wherein:

 scope "Deleted", :only_deleted scope "All", :with_deleted 
0
source

Source: https://habr.com/ru/post/915326/


All Articles