Reputation: 2279
All the examples of Kaminari I have seen only have 1 variable in the controller action.
But here is my example:
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
These are all displayed in a table on the view, which I want to paginate. Do I need to combine these into 1 array first in the index action?
My loop on the view is like this:
<% [@in_force_item, @draft_item, @historical_items].compact.flatten.each do |lo_item| %>
then I have code like:
<% if lo_item == @draft_item %>
Is this possible and still be able to call the line above>?
Thanks to the answer below, I was able to do it like this:
@total_items = Kaminari.paginate_array([@draft_item, @in_force_item, @historical_items].compact.flatten).page(params[:page]).per(10)
It all had to be on one line for it to work, unlike the answer below which had it split across two lines.
Upvotes: 0
Views: 167
Reputation: 10406
It is. Kaminari has paginate_array
@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)
Then
<% @total_items.each do |lo_item| %>
<% end %>
<%= paginate @total_items %>
Upvotes: 1