0

I have one error with Kaminari and Elasticsearch on rails app. I am unable to find the problem. I think my mistake is in my controller. By the way I am using active-admin for administrate my app.

undefined method `page' for "France":String

Elasticsearch.rb

case
when defined?(::Kaminari)
  Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari
when defined?(::WillPaginate)
  Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::WillPaginate
end

Controller:

def result
  if params[:q].nil?
    @campings = []
  else
    @campings = Camping.__elasticsearch__.search params[:q].page(params[:page]).per(14)
  end
end

Thanks for your help :)

Hizqeel
  • 947
  • 3
  • 20
  • 23
frontcodelover
  • 327
  • 2
  • 21

1 Answers1

1

The problem is you're calling the page method on params[:q] which is a string. You should enclose the call to search with brackets so that the page method will be called on the result of search and not on params[:q].

@campings = Camping.__elasticsearch__.search(params[:q]).page(params[:page]).per(14)

Hope this helps!

Arun Kumar Mohan
  • 11,517
  • 3
  • 23
  • 44