简体   繁体   English

Searchkick结果的未定义方法分页

[英]Undefined Method Paginate for Searchkick Results

undefined method `paginate' for 未定义的方法'paginate'

Unable to Paginate when using searchkick 使用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. 这似乎是由于Searchkick宝石引起的,使用常规的哑搜索时不会出现此问题。

You have to pass pagination params as #search parameters: 您必须将分页参数作为#search参数传递:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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