简体   繁体   English

未定义的方法“分页”问题

[英]undefined method `paginate' issue

I have the following code in my controller: 我的控制器中有以下代码:

def index
  @search = Product.search do |query|
    query.fulltext params[:sSearch]
    query.with(:store_id, @store.id)
  end
  products = @search.results.paginate(page).per_page(per_page)
end

private
  def page
     params[:iDisplayStart].to_i/per_page + 1
  end

  def per_page
     params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10
  end

but I get the error: 但是我得到了错误:

undefined method `paginate' for #<Sunspot::Search::PaginatedCollection:0x007f86243ac440>

Try to use within the search block: 尝试在搜索块中使用:

@search = Product.search do |query|
    query.paginate page: page, per_page: per_page
end

You do not need to use the query variable in the block. 您无需在块中使用查询变量。 You can invoke methods directly within the block. 您可以直接在块中调用方法。

@search = Product.search do
    fulltext params[:sSearch]
    with(:store_id, @store.id)
    paginate page: page, per_page: per_page
end

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

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