我看到的所有Kaminari示例在控制器操作中只有一个变量。
但我的例子是:
def index
@draft_item = @account.draft_item # only ever one
@in_force_item = @account.in_force_item # only ever one
@historical_items = @account.lo_items.historical # many of these
respond_to do |format|
format.html
end
end所有这些都显示在视图中的一个表中,我想对其进行分页。我是否需要首先在索引操作中将它们组合成一个数组?
我在视图上的循环如下:
<% [@in_force_item, @draft_item, @historical_items].compact.flatten.each do |lo_item| %>我有这样的代码:
<% if lo_item == @draft_item %>这是否有可能,并且仍然能够调用线路above>?
多亏了下面的回答,我才能这样做:
@total_items = Kaminari.paginate_array([@draft_item, @in_force_item, @historical_items].compact.flatten).page(params[:page]).per(10)这一切都必须在一条线上才能起作用,不像下面的答案把它分成两条线。
发布于 2015-06-26 13:01:00
它是。卡米纳里有数组
@draft_item = @account.draft_item # only ever one
@in_force_item = @account.in_force_item # only ever one
@historical_items = @account.lo_items.historical
@total_items = [@in_force_item, @draft_item, @historical_items].compact.flatten
Kaminari.paginate_array(@total_items).page(params[:page]).per(10)然后
<% @total_items.each do |lo_item| %>
<% end %>
<%= paginate @total_items %>https://stackoverflow.com/questions/31073734
复制相似问题