Reputation: 61
I have set-up will_paginate to paginate an array (list of customer orders) and am using the following code in my show view (the orders are nested on the seller's page);
<ol>
<% @seller.trans.paginate(:page => 1, :per_page => 6).each do |buy| %>
<li><%= buy.customer.name %>£<%= buy.sum %><%= buy.date %></li>
<% end %>
</ol>
This has placed the right restriction on the array (6 per page) and I can manually filter through by changing the page number to 1, 2 or 3 (I have 13 orders) but the 'Next/Previous' links are missing from the view.
What is it I'm doing incorrectly? Thanks.
Upvotes: 0
Views: 547
Reputation: 1692
i think the code should be something like this
<ol>
<% @buys = @seller.trans.paginate(:page => 1, :per_page => 6) %>
<% @buys.each do |buy| %>
<li><%= buy.customer.name %>£<%= buy.sum %><%= buy.date %></li>
<% end %>
</ol>
<%= will_paginate(@buys) %>
take a look at the man page of the will_paginate gem from here, https://github.com/mislav/will_paginate
Upvotes: 2
Reputation: 144
Okey, so this is how I would go about it:
View:
<%= will_paginate @seller, renderer: BootstrapPagination::Rails %>
Controller:
@seller = *Model*.paginate(:page => params[:page], :per_page => 6);
This has been tested using the gem will_paginate-bootstrap
Good luck!
Upvotes: 0