我正在使用Mongoid和Devise设置我的第一个应用程序。我正试图在我的测试中为这个工厂生产一个用户:
Factory.define(:user) do |f|
f.email "bob1234@example.com"
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
如何在不创建任何嵌入文档的情况下创建用户模型?