ActiveAdmin - 显示关联模型的属性

ActiveAdmin - show attributes from association model

我有 Registration 个模型 has_many 个玩家 {Player}。注册有注册人的名字字段和姓氏字段,一个Playernamedate_of_birthclub等字段。从用户的角度来看,可以在注册表中添加最多 3 名玩家,因此 Registration 将始终最多有 3 名玩家。

现在,在 Active Admin 的 Registration 索引视图中,我想显示这 3 个玩家的属性,有点像这样。

注册

First_name | Last name | Players           |
                         Name : ...     
                         Date of birth: ...
                         Club :...

                         Name: ...
                         Date of birth: ...
                         Club :...

或者像这样。

First_name | Last name | Player name | Player date of birth | ...  | Player name | Player date of birth |

虽然我认为第一种方式会更好。

所以我的 Registration 最多可以关联 3 个玩家,我想在注册索引页面上显示玩家属性。

这可能吗?

您可以构建一个方法来显示带有行分隔符的玩家详细信息

def show_players
  players.map do |player|
    "name: #{player.name}\ndob: #{player.date_of_birth}\nclub:#{player.club}\n"
  end.join("\n")
end

然后在您的管理索引块中包含方法

column :show_players