【发布时间】:2012-12-03 10:38:45
【问题描述】:
在我的 rails 应用程序中,当存在关联时,我无法保存模型对象。 我正在使用 mongo 作为数据库。 简要说明:
我有一个模型对象,
@obj1 = User.create(name: "name1")
当我执行@obj1.save 时,它工作正常。现在我添加了一个关系说,
has_many :offices
然后我尝试使用新条目保存相同的对象。
@obj1 = User.create(name: "name2")
我收到类似
的错误 /gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:230:in `block in constantize'
gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:229:in `each'
编辑:
完整的错误跟踪:
NameError: uninitialized constant Office
from /home/workspace/.rvm/gems/ruby-1.9.3-p286@cv_app/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:230:in `block in constantize'
from /home/workspace/.rvm/gems/ruby-1.9.3-p286@cv_app/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:229:in `each'
from /home/workspace/.rvm/gems/ruby-1.9.3-p286@cv_app/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:229:in `constantize'
from /home/workspace/.rvm/gems/ruby-1.9.3-p286@cv_app/gems/activesupport-3.2.9/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
【问题讨论】:
-
你能发布实际的错误信息吗?您只发布了跟踪的一部分(它的来源),而不是实际的错误。
-
是否有一个
Office类可以关联?该错误表明它正在寻找该关联的另一端,但没有找到任何要关联的类。 -
@Shadwell 肯定有一个办公室类,但我仍然应该能够对 db 进行独立的用户条目..
-
@shioyama 我已经更新了 qsn..
标签: ruby-on-rails ruby activesupport model-associations