1
votes

I want to customize my filter in activeadmin panel for applications panel. currently i have a filter like this. Current i have filter like this

and want the filter like this

enter image description here

i do the code for this as follow

For add category element in filter i do as follow code.

There is 3 tables called

  1. applications
  2. categories
  3. application_categories

and i want the filter data from application_categories as per selection on category from filter.

Structure of tables as follow.

  1. applications table :

    1. id
    2. name
    3. status
    4. developer_id
    5. version
    6. language_id ,etc...
  2. categories table

    1. id
    2. name
    3. parent_id
  3. application_categories table

    1. id
    2. application_id
    3. category_id

In activeadmin resource file
app/admin/applications.rb file code

filter :status, :as => :select, :collection => ["pending", "approved", "declined"]
filter :featured, :as => :select
filter :developer, :collection => proc {(Developer.all).map{|d| [d.company_name, d.id]}}
filter :category , :collection => proc {(Category.all).map{|c| [c.name,c.id]}}
filter :name
filter :version
filter :tags

In application model file
in model app/models/application.rb

belongs_to :developer
belongs_to :bundle
belongs_to :license
belongs_to :language
belongs_to :category

has_many :application_categories, :dependent => :destroy
has_many :categories, :through => :application_categories

It’s display category element in filter panel, but when we select any category and click on filter it’s generate an error as shown below :

Mysql2::Error: Unknown column 'applications.category_id' in 'on clause': SELECT COUNT(DISTINCT count_column) FROM (SELECT applications.id AS count_column FROM applications LEFT OUTER JOIN categories ON categories.id = applications.category_id WHERE categories.id = 32 LIMIT 30 OFFSET 0) subquery_for_count

1

1 Answers

0
votes

In app/admin/applications.rb:

filter :categories

In app/models/application.rb: delete belongs_to :category

If it doesn't work, you have to update your ActiveAdmin gem: bundle update