简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM