I am working on ActiveAdmin and I am trying to display a column name Active Jobs
with a count
There are three models involved in getting this count
1. Staffroom
2. StaffroomPage
3. Job
class StaffroomPage < ActiveRecord::Base
belongs_to :staffroom
class Staffroom < ActiveRecord::Base
has_one :staffroom_page
has_many :jobs
class Job < ActiveRecord::Base
belongs_to :staffroom
Now inside the admin/staffroom_pages.rb
I am able to display the column and the count
column :active_jobs, sortable: 'active_jobs' do |staffroom_page|
staffroom_page.staffroom.jobs.where(:state=> 'active').count
end
However I am not able to sort the data via active_jobs
and I see the following error
PG::UndefinedColumn: ERROR: column "active_jobs" does not exist
So the question is how to make the sort to work for column active_jobs
, please note that this is not the only sortable column on page, almost all columns are sortable and this is the only one not working.