ruby-on-rails - MongoID 为任何异常抛出错误数量的参数。Ruby 3.0.0 + Rails 6.1.3.1
问题描述
我的堆栈是
Ruby 3.0.0 Rails 6.1.3.1 Mongoid 7.1.2
Mongo 在应该引发其他异常时总是抛出相同的异常:
ArgumentError (wrong number of arguments (given 3, expected 1..2))
例如:
我对字段进行了唯一性验证:
irb(main):010:0> Model.create!(field: 'sape')
=> #<Model _id: 606207343dcde26a1595eb48, created_at: 2021-03-29 16:58:28.006091 UTC, updated_at: 2021-03-29 16:58:28.006091 UTC, field: "sape">
irb(main):011:0> Model.create!(field: 'sape')
Traceback (most recent call last):
1: from (irb):11:in `<main>'
ArgumentError (wrong number of arguments (given 3, expected 1..2))
find_by 也一样:如果响应找到一个,它会检索它:
irb(main):012:0> Model.find_by(field: 'sape')
=> #<Model _id: 606207343dcde26a1595eb48, created_at: 2021-03-29 16:58:28.006 UTC, updated_at: 2021-03-29 16:58:28.006 UTC, field: "sape">
但如果它不存在:
irb(main):001:0> Model.find_by(field: 'sape')
Traceback (most recent call last):
1: from (irb):1:in `<main>'
ArgumentError (wrong number of arguments (given 2, expected 0..1))
这是我的模型:
class Model
include ActiveModel::Validations
include Mongoid::Document
include Mongoid::Timestamps::Created
include Mongoid::Timestamps::Updated
field :field, type: String, default: nil
index({ field: 1 }, { unique: true })
end
解决方案
Ruby 3 目前不受 Mongoid 支持,不应使用。
您可以在此处查看哪些 Rubies Mongoid 支持。
推荐阅读
- spring - 在spring mvc+spring security+spring session redis web应用中同时使用WebApplicationInitializer和web.xml
- google-apps-script - 加载 Google App 脚本库时出现问题 - 出现未知函数错误
- mysql - 如何防止 mySQL 自动增量在 Django 中重置
- reactjs - 如何根据数组内对象的属性返回元素
- multithreading - 如何在后台加载资源?
- r - 在R中提取带有上下文的字符串
- c# - 将 jQuery JSON 对象保存到 SQL 表中,而无需在 MVC ASP.NET Core 中创建视图模型类
- javascript - 我想使用按钮更改我的 UL 中的某些名称
- c++ - gcc在其所在目录下找不到libcurl头文件
- c# - C# - 在多行文本框上绘制网格线