How To Paginate Shopify App Using Ruby On Rails

I am working on a Shopify embedded app following the Shopify tutorial:

I want to display orders table in my app but since there will be too many orders I need somekind of table with pages in my app.

I am really new to Ruby so I tried to achieve this with javascript only but I will have to load all orders which is what I want to avoid in the end.

Can someone guide me please!!



Pagination is key. Will_paginate is a common gem for Ruby on Rails. If you can add gems to your Gemfile, look up will_paginate and include it in your file. Then you can paginate Order items like:

@orders = Order.paginate(page: params[:page], per_page: 15)

And in your view.html.erb

<%= will_paginate @orders %>

It only loads the per_page amount of @orders. So it's fast and easy to setup.