Search code examples
mongodbmongoidruby-on-rails-4ransack

Does ransack gem work for MongoDB? undefined method `result' for nil:NilClass


Does ransack gem work for MongoDB?

I have customized below to my case:

def index
  @q = Person.search(params[:q])
  @people = @q.result(distinct: true)
end

I'm having error: undefined method `result' for nil:NilClass

Here https://github.com/ernie/ransack it describes about ActiveRecord and nothing is mentioned that it will work only for ActiveRecord...


Solution

  • You can see on their list of adapters that they only support active record versions, I am not familiar with that gem, but as fair as I understood, it generates queries on the database. As mongodb is not a relation database, it doesn't understand SQL, so the gem wont work at all.