1
votes

I am trying to map the name attribute from an array of ID's in my index view within active admin.

I have

Sector Model

has_many :portfolio_sectors
has_many :portfolios, through: :portfolio_sectors

Portfolio Model

has_many :portfolio_sectors
has_many :sectors, through: :portfolio_sectors

Portfolio Sector

belongs_to :portfolio
belongs_to :sector

Within active admin, at the moment, I have

# Index
index do
  selectable_column
  column :sector_ids
  actions
end

which will return

[2, 3]

I have the ID's of my sectors. How can I display the name attribute? Using map gives me

undefined method `map` for fixnum 2

How do I access name?

1
Which model is the index page for where you are trying to do this? Is it Portfolio? - rlarcombe
This is same as this question : stackoverflow.com/questions/15832022/… - SSR

1 Answers

1
votes

Column accepts a block.

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