Skip to content

Commit

Permalink
Fix will_paginate crash when Meilisearch disabled
Browse files Browse the repository at this point in the history
Using Meilisearch::Rails.active? as an alternative to checking that the
objects being replaced are actually NullObject.

For an alternative solution see meilisearch#383

The advantage of this approach is that NullObject remains opaque and
requires no special treatment, and the logic is much easier to follow
(in my opinion).
  • Loading branch information
ellnix committed Jan 14, 2025
1 parent fae9961 commit d3cce03
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/meilisearch/rails/pagination/will_paginate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module Rails
module Pagination
class WillPaginate
def self.create(results, total_hits, options = {})
unless MeiliSearch::Rails.active?
total_hits = 0
options[:page] = 1
options[:per_page] = 1
end

::WillPaginate::Collection.create(options[:page], options[:per_page], total_hits) do |pager|
pager.replace results
end
Expand Down

0 comments on commit d3cce03

Please sign in to comment.