Skip to content

Commit e9cf005

Browse files
committed
Fix will_paginate crash when Meilisearch disabled
When Meilisearch is disabled, NullObject is passed to will_paginate when it expects integers.
1 parent 1eaa408 commit e9cf005

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/meilisearch/rails/pagination/will_paginate.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ module Rails
1010
module Pagination
1111
class WillPaginate
1212
def self.create(results, total_hits, options = {})
13+
total_hits = 0 if Utilities.null_object?(total_hits)
14+
options[:page] = 1 if Utilities.null_object?(options[:page])
15+
options[:per_page] = 1 if Utilities.null_object?(options[:per_page])
16+
1317
::WillPaginate::Collection.create(options[:page], options[:per_page], total_hits) do |pager|
1418
pager.replace results
1519
end

lib/meilisearch/rails/utilities.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ def sequel_model?(model_class)
5656
defined?(::Sequel::Model) && model_class < Sequel::Model
5757
end
5858

59+
def null_object?(obj)
60+
obj.is_a? NullObject
61+
end
62+
5963
private
6064

6165
def constraint_passes?(record, constraint)

0 commit comments

Comments
 (0)