I couldn't find this in the docs, but it's likely there and I missed
it. To display a custom attribute for associated records, define a
'name_for_admin_assistant' method. Otherwise, it will look for (in
order) a method named :name, :title, :login, or :username (likely
coming from the database courtesy of ActiveRecord), using the first
one that responds.
For example:
class Subtenant < ActiveRecord::Base
has_many :applications, :dependent => :destroy
def name_for_admin_assistant
sub_tenant_name
end
end
class Application < ActiveRecord::Base
belongs_to :subtenant
end
class Admin::ApplicationsController < ApplicationController
admin_assistant_for Application do |aa|
aa.actions << :destroy
end
end
Now the URL '/admin/applications' will use
Subtenant.name_for_admin_assistant to display the various Subtenant
values
Here's the admin_assistant code that handles this:
# association_target.rb
def assoc_value(assoc_value)
if assoc_value.respond_to?(:name_for_admin_assistant)
assoc_value.name_for_admin_assistant
elsif assoc_value && default_name_method
assoc_value.send default_name_method
end
end
def default_name_method
[:name, :title, :login, :username].detect { |m|
@associated_class.columns.any? { |column| column.name.to_s ==
m.to_s }
}
end
I hope this helps someone.
Thanks for admin_assistant!
/g
--
George Anderson
BenevolentCode LLC
geo...@benevolentcode.com