ruby on rails - Displaying has_many through association as column in Active Admin index -
how display list of has_many_through associations association column headings , through: value entry in table row?
i have 3 models:
class jobs attr_accesor :title has_many :scores has_many :factors, through: :scores end class scores attr_accesor :score belongs_to :job belongs_to :factor end class factor attr_accesor :name has_many :scores has_many :jobs, through: :scores end
i want able show, in jobs index, row each job, title of each factor column heading, , scores of each job value in cell.
i expect have in app/admin/jobs.rb
file:
index |jobs| column :title jobs.scores.each |score| column(score.factor.name) { |score| score.score } end end
and output this:
job | education | experience | leadership | ... | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ceo | 600 | 720 | 580 | ... | admin assistant | 210 | 200 | 150 | ... |
but activeadmin doesn't seem jobs.scores.each
line, giving me following error:
undefined method `scores' #<activeadmin::views::indexastable::indextablefor:0x00000104d1dad0>
if understand data correctly think work. can each on 1 line, if doesn't work map or collect. can chain each , map. ensure you're using compact don't hit nils. below i'm assuming score.factor.name equal each column should named , data filled in.
index |jobs| column :title column "education" |job| job.scores.map { |score| score if score.factor.name == "education" }.compact end column "experience" |job| job.scores.map { |score| score if score.factor.name == "experience" }.compact end end
Comments
Post a Comment