Nicky Feller Nicky Feller - 1 month ago 21
Ruby Question

Undefined Method Paginate for Searchkick Results


undefined method `paginate' for




Unable to Paginate when using searchkick

if params[:search].present?
@courses = Course.search(params[:search]).paginate(page: params[:page], per_page: 3)
else
@courses = Course.paginate(page: params[:page], per_page: 3)
end


When the conditional skips to else. it can render and paginate no problem. But when it is subject to search it refuses to paginate. It seems to be due to the Searchkick gem, this problem does not arise when using regular dumb search.

Answer

You have to pass pagination params as #search parameters:

@courses = Course.search(params[:search], page: params[:page], per_page: 3)

https://github.com/ankane/searchkick#pagination