ruby-on-railsruby-on-rails-4paginationwill-paginate

will_paginate gem : Limit number of pages


enter image description here

This is my pagination, I want to limit the number of pages to 10, for example, to don't have the same problem as in the picture.

How can I do it using will_paginate gem?


Solution

  • The following command:

    <%= will_paginate @yourwhatevers, inner_window: 3, outer_window: 1 %>
    

    accomplishes this. Let's say you are on page 15 of 36, you will get:

    Previous 1 2 ... 12 13 14 15 16 17 18 .. 35 36 Next
    

    inner_window, in other words how many to the right and left from current page, defaults to 4, but for better, you could make it 1 or 2. outer_window defaults to 1, so my line above could not contain it at all