【问题标题】:Rails: Cannot create new documents with MongoMapperRails:无法使用 MongoMapper 创建新文档
【发布时间】:2018-06-07 04:24:20
【问题描述】:

我一直在使用带有 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)

请帮忙!

【问题讨论】:

    标签: ruby-on-rails mongomapper


    【解决方案1】:

    Mongomapper 与 Rails 5.2 不兼容

    【讨论】:

    • 你能详细说明你的答案吗?也许建议其他解决方案或提出如何解决 OP 问题的建议?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多