Skip to content

Commit d06b68d

Browse files
committed
Fix will_paginate crash when Meilisearch disabled
Using Meilisearch::Rails.active? as an alternative to checking that the objects being replaced are actually. For an alternative solution see meilisearch#383 The advantage of this approach is that NullObject remains opaque, and the logic is much easier to follow (in my opinion).
1 parent fae9961 commit d06b68d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/meilisearch/rails/pagination/will_paginate.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ module Rails
1010
module Pagination
1111
class WillPaginate
1212
def self.create(results, total_hits, options = {})
13+
unless MeiliSearch::Rails.active?
14+
total_hits = 0
15+
options[:page] = 1
16+
options[:per_page] = 1
17+
end
18+
1319
::WillPaginate::Collection.create(options[:page], options[:per_page], total_hits) do |pager|
1420
pager.replace results
1521
end

0 commit comments

Comments
 (0)