Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建具有关联的Ruby ActiveRecord对象_Ruby_Activerecord_Polymorphic Associations - Fatal编程技术网

创建具有关联的Ruby ActiveRecord对象

创建具有关联的Ruby ActiveRecord对象,ruby,activerecord,polymorphic-associations,Ruby,Activerecord,Polymorphic Associations,我有人和团队有地址(多态关联) 我需要在代码中分别创建人员和地址: person=person.new address=address.new 然后使用如下方式将它们连接在一起: person.addressable.push(地址) 最后,要做: 救命! 然而,当你没有预料到它的时候,这给了你一个零的对象! 计算nil时出错。是否有密钥 有人能告诉我我需要做什么吗?google上几乎没有代码演示这一切,我只能找到API参考,发现了这个问题-我在Address类中重写了initi

我有人和团队有地址(多态关联)

我需要在代码中分别创建人员和地址:

person=person.new

address=address.new

然后使用如下方式将它们连接在一起:



person.addressable.push(地址)

最后,要做:


救命!

然而,当你没有预料到它的时候,这给了你一个零的对象! 计算nil时出错。是否有密钥


有人能告诉我我需要做什么吗?google上几乎没有代码演示这一切,我只能找到API参考,发现了这个问题-我在Address类中重写了initialize。我发现这是最愚蠢的事情:-(