2
我有點奇怪的命名空間錯誤處理FactoryGirl
。該型號爲Post ⤞ User
。 的代碼是:FactoryGirl錯誤:未初始化的常量Post :: user
require 'factory_girl'
require 'active_record'
class User < ActiveRecord::Base ; end
class Post < ActiveRecord::Base
has_one :moderator, class_name: :user
end
::FactoryGirl.define do
factory :user do
name 'Ghghghgh Ghghg'
end
factory :post do
text 'Lorem ipsum etc'
association :moderator, factory: :user, strategy: :create
end
end
,要求精細,返回true
。現在,當我嘗試生成實例時,出現此錯誤:
FactoryGirl.create :post
#⇒ NameError: uninitialized constant Post::user
我錯過了什麼?
哦,是的,謝謝。我混淆了事物,並繼續以'FactoryGirl'的方式編寫AR代碼。新鮮的眼睛是一種強大的力量。謝謝。 – mudasobwa