为什么我得到“未定义的方法`assert_valid_keys`”?

知道为什么我收到此错误:

Exception encountered: # 

当我尝试在以下模型上执行Factory.build(:widget)时:

 class Widget < ActiveRecord::Base belongs_to :designer, :vendor # ... end 

当我删除belongs_to行时,错误消失了。

  belongs_to :designer, :vendor 

不行。 :vendor被视为一种选择。 当然,没有这样的选择。 有关详细信息,请参阅文档 。

如果您需要两个belongs_to关系,只需将您的代码更改为:

  belongs_to :designer belongs_to :vendor