Reputation: 2198
I have Registration
model that has_many
players {Player}
. Registration has registerer's first name field and last name field, and a Player
has such fields as name
, date_of_birth
, club
. From users's perspective it is possible to add up to 3 players on the registration form so a Registration
will always have up to 3 players.
Now, in Active Admin on Registration
Index view I would like to show those 3 players' attributes, somehow like this.
Registration
First_name | Last name | Players |
Name : ...
Date of birth: ...
Club :...
Name: ...
Date of birth: ...
Club :...
Or maybe like this.
First_name | Last name | Player name | Player date of birth | ... | Player name | Player date of birth |
Though I think the first way would be better.
So my Registration
can have max 3 players associated with it and I would like to display players attributes on Registration index page.
Is this possible?
Upvotes: 0
Views: 639
Reputation: 36860
You could build a method that displays the player details with line separators
def show_players
players.map do |player|
"name: #{player.name}\ndob: #{player.date_of_birth}\nclub:#{player.club}\n"
end.join("\n")
end
Then in your admin index block include the method
column :show_players
Upvotes: 1