Skip to content

Commit 2488e26

Browse files
bendangelocurquiza
authored andcommitted
For kaminari total_hits defaults to zero
1 parent d0a6f1a commit 2488e26

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/meilisearch/rails/pagination/kaminari.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ def initialize(array, options)
1919

2020
def self.create(results, total_hits, options = {})
2121
offset = ((options[:page] - 1) * options[:per_page])
22-
array = new results, limit: options[:per_page], offset: offset, total_count: total_hits
22+
total_hits = 0 if total_hits.nil?
23+
offset = 0 if offset.nil?
24+
limit = 0 if options[:per_page].nil?
25+
array = new results, limit: limit, offset: offset, total_count: total_hits
2326

2427
if array.empty? && !results.empty?
2528
# since Kaminari 0.16.0, you need to pad the results with nil values so it matches the offset param
2629
# otherwise you'll get an empty array: https://github.com/amatsuda/kaminari/commit/29fdcfa8865f2021f710adaedb41b7a7b081e34d
2730
results = Array.new(offset) + results
28-
array = new results, offset: offset, limit: options[:per_page], total_count: total_hits
31+
array = new results, offset: offset, limit: limit, total_count: total_hits
2932
end
3033

3134
array

0 commit comments

Comments
 (0)