- Published on
- • 1 min read
ActiveAdmin- adding a filter on has_one through association
- Authors

- Name
- Shaiju Edakulangara
- @eshaiju
Given Project, Task, and Activity, I've managed to set up a has_one :through relationship filter with the following:
class Project < ActiveRecord::Base
has_many :tasks
end
class Task < ActiveRecord::Base
belongs_to :project
has_many :activities, :dependent => :destroy
end
class Activity < ActiveRecord::Base
has_many :tasks
has_one :project, through: :task
end
In your ActiveAdmin file:
ActiveAdmin.register User do
filter :task_project_id, as: :select, collection: Project.all, label: 'Project'
end