【发布时间】:2009-08-28 23:44:31
【问题描述】:
我的人员和团队有地址(多态关联)
我需要在代码中分别创建人员和地址:
person = Person.new
address = Address.new
然后使用类似的东西将它们链接在一起:
person.addressable.push(address)
最后,做:
person.save!
然而,当你没想到它时,这会给出一个你有一个 nil 对象! 评估 nil.has_key 时发生错误?
有人可以告诉我我需要做什么吗? google 上很少有代码可以演示这些,我能找到的只是 API 参考
【问题讨论】:
标签: ruby activerecord polymorphic-associations