【问题标题】:Mapping `has_many` in active admin在活动管理员中映射“has_many”
【发布时间】:2015-11-23 10:19:03
【问题描述】:

我正在尝试从活动管理员的索引视图中的 ID 数组映射name 属性。

我有

行业模型

has_many :portfolio_sectors
has_many :portfolios, through: :portfolio_sectors

投资组合模型

has_many :portfolio_sectors
has_many :sectors, through: :portfolio_sectors

投资组合领域

belongs_to :portfolio
belongs_to :sector

目前,在活跃的管理员中,我有

# Index
index do
  selectable_column
  column :sector_ids
  actions
end

将返回

[2, 3]

我有我的部门的 ID。如何显示name 属性?使用map 给了我

undefined method `map` for fixnum 2

如何访问name

【问题讨论】:

标签: ruby-on-rails ruby activeadmin


【解决方案1】:

accepts a block

column "Sectors" do |portfolio|
  portfolio.sectors.map(&:name)
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-04
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 2011-11-27
    • 2012-03-23
    • 2018-04-18
    相关资源
    最近更新 更多