我是工厂机器人的新手,我尝试使用工厂机器人创建一个示例数据,但是我收到了这个错误
如何解决此错误?
功能/支持/ factories.rb:
require 'factory_bot'
FactoryBot.define do
factory :user do
email "[email protected]"
password "asdf123"
password_confirmation "asdf123"
end
end
FactoryBot.define do
factory :post do
user = FactoryBot.create(:user)
end
end
要求'factory_bot'
FactoryBot.define do
factory :user do
email "[email protected]"
password "asdf123"
password_confirmation "asdf123"
end
end
FactoryBot.define do
factory :post do
user
end
end
如FactoryBot文档中所述
Associations
可以在工厂内建立关联。如果工厂名称与关联名称相同,则可以省略工厂名称。
factory :post do
# ...
author
end
您还可以指定其他工厂或覆盖属性:
factory :post do
# ...
association :author, factory: :user, last_name: "Writely"
end