升级到Rails 5和Mongoid 7后出现NoMethodError洗劫

问题描述 投票:0回答:1

升级到Rails 5和Mongoid 7后,我的Ransack对于班级不可见。例如代码:

users = User.ransack(params[:q])
render json: users

应用程序因错误而崩溃

NoMethodError (undefined method `ransack' for User:Class)

[在Rails 4.2和Mongoid 4上一切正常。

当前Gemfile:

ruby '2.5.1'
gem 'rails', '5.2.0'
gem 'ransack', git: 'https://github.com/activerecord-hackery/ransack', require: 'mongoid' (version 1.8.8)
gem 'mongoid', '~>7' (version 7.0.1)

有什么想法吗?

ruby-on-rails mongoid ransack
1个回答
0
投票

对我来说,解决方案是添加

gem 'ransack-mongoid', github: 'activerecord-hackery/ransack-mongoid'

到Gemfile。它尚未维护,将来可能会在寻找维护者时停止使用。

它再次增加了对蒙古包的支持。但是,我无法选择任何数据,得到

User.ransack().result throws

Mongoid::Errors::CriteriaArgumentRequired - message:
  Calling Criteria methods with nil arguments is not allowed.
summary:
  Arguments to Criteria methods cannot be nil, and most Criteria methods require at least one argument. Only logical operations (and, or, nor and not), `all' and `where' can be called without arguments. The method that was called with nil argument was: where.
resolution:
  Invoke Criteria methods with non-nil arguments or omit the respective invocations.:

由于我也必须解决此问题,因此我将对其进行更多研究。

© www.soinside.com 2019 - 2024. All rights reserved.