出于某种原因,我一碰到代码就会收到错误

时间:2018-04-26 14:56:51

标签: ruby-on-rails ruby ruby-on-rails-3

出于某种原因,我一碰到代码就会收到错误。

def skill_list
    array = skill_associations.map do |sa|
     sa.skill.names // this is where I get error  
    end
   array.join(", ")
end

def skill_list=(names)
    self.skill_associations.delete_all
    self.skills = names.split(",").map do |m|
      Skill.where(name: m.strip).first_or_create!
    end
end

1 个答案:

答案 0 :(得分:0)

可能你需要:

skill_associations.map(&:skill).compact.map(&:name).compact.join(", ")