Filter on parent object attribute in ActiveAdmin

David Moulton picture David Moulton · Oct 27, 2011 · Viewed 10.7k times · Source

I'd like to be able to filter an object based on an attribute of it's parent:

class Call < ActiveRecord::Base
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :calls
end

I'd like to be able to do this:

ActiveAdmin.register Call do
  filter :user
end

and have it filter on user.name, rather than present a select of all users. Can this be done?

Answer

Justin Thiele picture Justin Thiele · Jan 11, 2012

Denis's solution almost worked for me. I just needed to add the filter type. For example:

ActiveAdmin.register Call do
  filter :user_name, :as => :string
end