I want to customize my filter in activeadmin panel for applications panel. currently i have a filter like this.
and want the filter like this
i do the code for this as follow
For add category element in filter i do as follow code.
There is 3 tables called
and i want the filter data from application_categories as per selection on category from filter.
Structure of tables as follow.
applications table :
categories table
application_categories table
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.