2

I'm making a Spree site that has links for changing the number of products per page including a link for All. The links for a number are easy because I can just pass a :per_page param via the query string and helper methods. However, I can't figure out what I need to pass to either tell Kaminari to not paginate or to temporarily disable Kaminari.

I'm happy for a solution either in Spree or in Kaminari. I would prefer a method other than :per_page = 1000 or some similarly large number.

  • Spree 0.70.3
  • Kaminari 0.13.0
4

3 回答 3

1

你能传递一个查询字符串参数,然后在你的控制器动作中过滤它吗?例如:

def show
  @products = unless params[:show_all]
    Product.page(params[:page]).per(params[:per_page])
  else
    Product.all
  end
end

我知道这并不能在 Spree 或 Kaminari 中为您提供解决方案,但它可能有助于解决这个问题。不过,我很想知道图书馆是否有另一种内置方式。

于 2012-06-06T06:49:03.167 回答
1

试试这个来处理未定义的方法'current_page'

=paginate @object if @object  && @object.try(:total_pages)
于 2016-08-01T11:14:08.100 回答
0

这就是我一直在做的事情,因为我需要 kaminari 添加到记录列表中的辅助方法:

params[:per] = Product.count if params[:per] == 'all'
Product.page(params[:page]).per(params[:per])

这将避免undefined method 'current_page' for #<Array:0x007fc6157c16a8>错误。(基本上是@Yogh 在另一个答案的评论中的建议。)

于 2014-09-15T17:08:29.770 回答