1
votes

I'm struggling with filters on the index view of my ActiveAdmin resource.

This is the abbrieviated source:

ActiveAdmin.register PendingCollege do
  config.clear_action_items!

  controller do
    include Sendable
  end

  filter :name

  menu :parent => "College"

  actions :all, :except => [:destroy, :edit]

  scope :all do
    PendingCollege
  end

  scope :pending, default: true do
    PendingCollege.pending
  end

  scope :rejected do
    PendingCollege.rejected
  end

  scope :accepted do
    PendingCollege.accepted
  end

  index do
    column :id
    column "Name", :name
    column "IPEDS Number", :ipeds_number
    column "Local id", :local_id
  end
end

The behavior I am seeing is that the filter shows up on the right as expected. When I select 'contains' and put a string in the box and hit the filter button, it reloads the page with the default scope but the results have not been filtered at all.

I verified that "q"=>{"name_contains"=>"Adrian"} is in the parameters to the controller, but the sql being run doesn't leverage that.

I basically added a single filter (rather than the default filters for every attribute) because there are TONS of searchable attributes that I don't need to expose in this interface.

I've looked at lots of code examples and haven't found anything where extra code had to be added to support the filters.

1
To clarify, Sendable is a module that has methods to send data to a remote RESTful api via http. - jaydel

1 Answers

0
votes

You should define scopes like this:

scope :pending, default: true do |scope|
  # given scope has all applied filters at this moment
  scope.pending
end

In your case, since you have scopes with the same name in your model, you can simply do like this:

scope :all
scope :pending, default: true
scope :rejected
scope :accepted