Skip to content

Kaminari Pagination with MultiModel Search #476

@rkrdo

Description

@rkrdo

This is related to #382
Using the code from master, I'm trying to make a MultiModel Search:
(Elasticsearch::Model.search('search term', [User, Admin]).page(params[:page]).records)

And that works fine, however, when trying to use Kaminari's paginate helper with the records collection, I'm getting the following error:

NameError - undefined local variable or method `max_pages' for #<Elasticsearch::Model::Response::Records:0x007f99cd59b258>:
   () .../bundler/gems/elasticsearch-rails-ded203569208/elasticsearch-model/lib/elasticsearch/model/response/records.rb:58:in `method_missing'
  kaminari (0.16.3) lib/kaminari/models/page_scope_methods.rb:27:in `total_pages'
  kaminari (0.16.3) lib/kaminari/helpers/action_view_extension.rb:18:in `paginate'

I noticed that the Kaminari configuration methods are getting included in Elasticsearch::Model::Response::Results but not on Elasticsearch::Model::Response::Records (see model/response/pagination.rb), so including the Kaminari methods in Elasticsearch::Model::Response::Records fixes my issue.

Is there a reason why those methods don't get included in Elasticsearch::Model::Records ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions