After upgrading to Rails 5 and Mongoid 7 my Ransack is not visible for classes. For example for code:
users = User.ransack(params[:q])
render json: users
application crashes with error
NoMethodError (undefined method `ransack' for User:Class)
Everything works fine on Rails 4.2 and Mongoid 4.
Current 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)
Any ideas?
For me the solution was to add
gem 'ransack-mongoid', github: 'activerecord-hackery/ransack-mongoid'
to the Gemfile. It is not maintained and might be discontinued in the future, as maintainer is searched for.
It adds the support for mongoid again. But, I'm unable to select any data, getting
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.:
Since I have to solve this issue as well, I'll be looking more into it.