ruby-on-rails - Rails:无法使用 MongoMapper 创建新文档
问题描述
我一直在使用带有 Rails 5.2 的 MongoMapper。创建模型:
class Item
include MongoMapper::Document
key :title, String
key :description, String
end
在 MongoDB 中,我插入了文档
{
"title": "demo",
"description": "this is the demo item"
}
使用 Rails 控制台测试这个模型
Item.where({:title => "demo"}).first
它显示结果是上面的文档。但是当我创建一个新文档时:
item = Item.create({:title => "demo2", :description => "the demo2"})
控制台中的错误
Traceback (most recent call last):
2: from (irb):3
1: from (eval):9:in `title='
NoMethodError (undefined method `[]' for nil:NilClass)
我尝试了该方法new
item = Item.new
控制台显示:
Traceback (most recent call last):
2: from (irb):4
1: from (irb):4:in `new'
NoMethodError (undefined method `keys' for nil:NilClass)
请帮忙!
解决方案
Mongoapper 与 rails 5.2 不兼容
推荐阅读
- c++ - 错误 LNK1104:无法打开文件 'aocl_utils.lib'
- python - 如何拆分一串名称和相邻的数字,以便将数字分配给每个相邻的字符串名称?
- angular - 如何等到调用服务构造函数并以角度完成执行
- c++ - 将 PDB(蛋白质数据库)文件直接导入虚幻引擎 4
- excel - 单击操作行后,单元格中的新格式会发生变化
- elasticsearch - 在 Elasticsearch/Lucene 中执行模糊查询时,是否最多创建 n^2 个字符串扩展?
- flutter-layout - 如何在 SliverAppBar Flutter 上自定义搜索栏
- python - 无法使用 Spotify 凭据来预测歌曲
- argo-workflows - 在类似于 Argocd 的 Argo 工作流程中启用对用户的匿名只读访问
- visual-studio - Visual Studio:意外的 PDB 错误;RPC (23)