Ruby 如何定义命名空间类的生成器

Ruby 如何定义命名空间类的生成器,ruby,mongoid,fabrication-gem,Ruby,Mongoid,Fabrication Gem,我想为具有类似“Foo::Bar”名称空间的类定义制造商。 告诉我它的工作方式 这是我的密码 模型/foo.rb class Foo include Mongoid::Document embedded_in :foo_container, polymorphic: true field :xxx .... end models/foo/bar.rb class Foo::Bar < Foo field :yyy .... field :zzz .... end

我想为具有类似“Foo::Bar”名称空间的类定义制造商。
告诉我它的工作方式

这是我的密码

模型/foo.rb

class Foo
  include Mongoid::Document
  embedded_in :foo_container, polymorphic: true

  field :xxx ....
end
models/foo/bar.rb

class Foo::Bar < Foo
  field :yyy ....
  field :zzz ....
end
当我试图在parino控制台上创建装配工对象时,出现了错误

> Fabricate(:foo_bar)
> NoMethodError: undefined method `new?' for nil:NilClass
  .... stack messages
当我试图创建另一个不是像“User”这样的命名空间类的制造商对象时,它成功了。

这对我来说很有效

Fabricator(:foo_bar, class_name: :'Foo::Bar') do
    xxx {Faker::Company.name}
    yyy 'Mystring'
end

根据制造部关于以下方面的文件:

要使用与类不同的名称,必须指定
from::symboliced_class_name
作为第二个参数

因此,以下措施应该有效:

Fabricator(:foo_bar, from: 'Foo::Bar') do
  yyy 'MyString'
  zzz 'MyString'
end
Fabricator(:foo_bar, from: 'Foo::Bar') do
  yyy 'MyString'
  zzz 'MyString'
end