【问题标题】:undefined method `paginate' issue未定义的方法“分页”问题
【发布时间】:2014-03-03 09:28:58
【问题描述】:

我的控制器中有以下代码:

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

但我得到了错误:

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

【问题讨论】:

  • 您是否使用分页 gem,如果是,请在您的问题中指定哪个
  • 是的,我正在使用 will_paginate

标签: ruby-on-rails ruby pagination sunspot will-paginate


【解决方案1】:

尝试在搜索块内使用:

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

您不需要在块中使用查询变量。您可以直接在块中调用方法。

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

【讨论】:

    猜你喜欢
    • 2013-06-10
    • 2013-10-12
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    • 2015-11-15
    • 1970-01-01
    • 1970-01-01
    • 2016-10-26
    相关资源
    最近更新 更多