ActiveAdmin - Using scopes with filters

activeadmin, formtastic, ruby-on-rails

Solution

Rather than scope create another filter which will select the records on criterion based on if examples are deleted or all. And apply as many filter as you want.

Or in filter while calculating the selector on which you will run the filter run the scope accordingly and then put the filter conditions on that selector.

Problem

In my ActiveAdmin model I have a custom scope to show deleted records and several filters for searching records by specific columns. Using the filters individually or combined together works as expected. Using a scope works as expected. The problem is that using a scope seemingly overrides all the filters and after selecting a scope any filter added does nothing. Anyone have any ideas here? What I want is to be able to show a specific scope and then still be able to filter results within that scope. ``` 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's the solution I've gone with. I set the with_deleted scope on the model and include filter on the side for showing/hiding deleted results. Not ideal since 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 ```

Original source

Related problems