Reputation: 13705
I have two models, Listing and Invitation, associated with has_and_belongs_to_many. I am looking at invitations through ActiveAdmin and would like to display the names of the associated listings. I attempt this with the following code:
ActiveAdmin.register Invitation do
index do
column("Listings") { |invitation| invitation.listings.each do |listing|
listing.name
end
}
default_actions
end
end
But nothing shows up. How can I get this to work?
Upvotes: 3
Views: 1758
Reputation: 2682
I am assuming that you want a single column with all the listings names of the invitation. Please try the following
column 'listing' do |invitation|
invitation.listings.collect(&:name).join(', ')
end
You might want to customize this later on and add a includes(:listings) to increase db retrieval performance.
Upvotes: 5