Search code examples
ruby-on-railsrubysearchwill-paginatesearchkick

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.


Solution

  • 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