Blog › Ruby

Tips: Multiple pagination with will_paginate

Will Paginate is a great and widely used gem for pagination in Ruby on Rails.

Sometimes you need to paginate multiple list on the same page.

This tip show you how to put a list of paginated products and a list of of paginated services on the same page with will_paginate.
The key point is to use a custom param param_name in the view and also in the controller

The view code is something like this:

1
2
3

# ...
# products list here
<%= will_paginate @products, :param_name => 'products_page', :prev_label => t('helpers.labels.previous'), :next_label => t('helpers.labels.next') %>

1

 

1
2
3

# services list here
<%= will_paginate @services, :param_name => 'services_page', :prev_label => t('helpers.labels.previous'), :next_label => t('helpers.labels.next') %>
# ...

And this is the code in the controller

1
2
3
4
5
6

# ...
def index
@products = current_company.products.paginate(:page => params[:products_page], :per_page => 10)
@services = current_company.products.paginate(:page => params[:services_page], :per_page => 10)
end
# ...

Save more time and effort by using this free and complete designer checklist.

Find out where AI can save your company time.

One hour with our team: we map your processes, pick 2-3 concrete use cases and tell you what is worth doing first. No strings attached.

Book a free AI assessment
Subsidised finance

Incentives and grants for your software or AI project.

With specialised partners we check which incentives your project can access and prepare the paperwork and the financing plan.

  • Hyper-depreciation for 4.0 and 5.0 assets
  • National and regional grants
  • Financing plan
Book a free AI assessment