Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.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 on rails 与FactoryGirl建立多态关联记录_Ruby On Rails_Factory Bot - Fatal编程技术网

Ruby on rails 与FactoryGirl建立多态关联记录

Ruby on rails 与FactoryGirl建立多态关联记录,ruby-on-rails,factory-bot,Ruby On Rails,Factory Bot,我想知道为什么我在使用FactoryGirl创建记录时出错 注释模型通过多态关联属于用户和可注释 我的工厂是这样的: FactoryGirl.define do factory :comment do text "Some text" user_id 1 association :commentable, factory: :feedback end end 当我使用FactoryGirl创建注释记录时,我得到: ActiveModel::MissingAttr

我想知道为什么我在使用FactoryGirl创建记录时出错

注释
模型通过多态关联属于
用户
可注释

我的工厂是这样的:

FactoryGirl.define do
  factory :comment do
    text "Some text"
    user_id 1
    association :commentable, factory: :feedback
  end
end
当我使用FactoryGirl创建
注释
记录时,我得到:

ActiveModel::MissingAttributeError:
can't write unknown attribute `commentable_type'
在控制台中创建和操作
Comment
对象没有问题。我可以自由设置和保存
commentable_type
属性。另外,
comments
表中已经存在
commentable\u type


关于错误发生的原因有什么想法吗?

我使用
rake db:reset
再次运行了所有迁移,现在错误消失了。在此之前,我曾尝试回滚相关的迁移并再次迁移,但没有做出任何更改


我仍然不知道是什么原因导致了这个错误,但现在,它已经被修复。

您在关系中有
as::commentable
吗?@Santosh我有
有很多:comments,as::commentable
。在控制台中,使用关联创建新的
注释
对象不会出现问题。有什么建议吗?同样的问题,同样的解决方案。这很奇怪。谢谢,你帮我省去了一些头痛!