Rails Kitchen

It's a place to write on stuff I learned recently.

ActiveAdmin- Adding a Filter on Has_one Through Association

| Comments

Given Project, Task, and Activity, I’ve managed to set up has_one :through relationship filter with the following:
1
2
3
class Project < ActiveRecord::Base
  has_many :tasks
end
1
2
3
4
class Task < ActiveRecord::Base
  belongs_to :project
  has_many :activities, :dependent => :destroy
end
1
2
3
4
class Activity < ActiveRecord::Base
  has_many :tasks
  has_one  :project, through: :task
end
1
2
3
ActiveAdmin.register User do
  filter :task_project_id, as: :select, collection: Project.all, label: 'Project'
end

Comments