升级到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)
有什么想法吗?
答案 0 :(得分:1)
对我来说,解决方案是添加
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.:
由于我也必须解决此问题,因此我将对其进行更多的研究。