Skip to content

Commit 26e05b8

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 26e05b8

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/meilisearch/rails/pagination/will_paginate.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ module MeiliSearch
99
module Rails
1010
module Pagination
1111
class WillPaginate
12+
1213
def self.create(results, total_hits, options = {})
14+
total_hits = 0 if Utilities.null_object?(total_hits)
15+
options[:page] = 1 if Utilities.null_object?(options[:page])
16+
options[:per_page] = 1 if Utilities.null_object?(options[:per_page])
17+
1318
::WillPaginate::Collection.create(options[:page], options[:per_page], total_hits) do |pager|
1419
pager.replace results
1520
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)