Skip to content

Instantly share code, notes, and snippets.

@lardawge
Created June 24, 2011 16:58
Show Gist options
  • Save lardawge/1045196 to your computer and use it in GitHub Desktop.
Save lardawge/1045196 to your computer and use it in GitHub Desktop.
Override to allow sunspot to return an array that can be used by Kaminari
module Sunspot
module Search
class AbstractSearch
private
def maybe_will_paginate(collection)
collection.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
def current_page
#{@query.page}
end
def num_pages
(#{total} / limit_value).ceil
end
def limit_value
#{@query.per_page}
end
RUBY
collection
end
end
end
end
@rafaelcgo
Copy link

Dunno if someone is still using this "patch" to add kaminari support.

On num_pages the way you're doing the expression is returning an integer to ceil() and it doesn't returns the expected value.
You need to change to:

(#{total}.fdiv(limit_value)).ceil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment