Factory Girl、Mongoid 和嵌入式文档
我正在使用 Mongoid 和 Devise 设置我的第一个应用程序。我正在尝试使用此工厂在我的测试中工厂化用户:
Factory.define(:user) do |f|
f.email "[email protected]"
f.password "testing"
f.password_confirmation "testing"
end
当我尝试工厂化此工厂时,我收到此错误:
NoMethodError: undefined method `add_on_blank' for []:Array
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/criteria.rb:213:in `send'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/criteria.rb:213:in `method_missing'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:373:in `send'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:373:in `method_missing'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/named_scope.rb:121:in `with_scope'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:372:in `send'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:372:in `method_missing'
我的模型如下所示:
用户:
class User
include Mongoid::Document
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
embeds_many :errors
end
错误:
class Error
include Mongoid::Document
field :klass, :type => String
embedded_in :user
end
如何在不同时创建任何嵌入文档的情况下创建用户模型?
I am setting up my first app with Mongoid and Devise. I am trying to Factory a user in my test with this factory:
Factory.define(:user) do |f|
f.email "[email protected]"
f.password "testing"
f.password_confirmation "testing"
end
When I try and factory this I get this error:
NoMethodError: undefined method `add_on_blank' for []:Array
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/criteria.rb:213:in `send'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/criteria.rb:213:in `method_missing'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:373:in `send'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:373:in `method_missing'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/named_scope.rb:121:in `with_scope'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:372:in `send'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:372:in `method_missing'
My models look like:
User:
class User
include Mongoid::Document
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
embeds_many :errors
end
Error:
class Error
include Mongoid::Document
field :klass, :type => String
embedded_in :user
end
How should a user model be created without creating any embedded documents at the same time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论