Rails 4 pagination, will_paginate vs. Kaminari using with bootstrap3
Asked Answered
C

3

16

I understand Kaminari perform well with Rails3 reading this article: Rails 3 pagination, will_paginate vs. Kaminari, but how about with Rails4? Also, when stylizing them with Bootstrap3, which gem is easier solution?

Cramoisy answered 29/1, 2014 at 8:49 Comment(0)
E
22

In my experience, there is very little difference between Kaminari & Will Paginate - it's mainly a personal choice as to which you use (rather like Paperclip / Carrierwave or Mac / Windows)

In terms of compatibility, both gems work natively with Rails 4


Bootstrap

In reference to Bootstrap, I think you're asking the wrong question

Bootstrap is a CSS framework, which has no bearing on the backend functionality of your app

Bottom line is you're going to have to call the pagination methods from your controller, and so the differences of the systems will only be cosmetic. If you use Bootstrap to stylize them, you'll have to do the same with either gem

So the choice is yours!

Eskimo answered 29/1, 2014 at 9:8 Comment(1)
Since they both have helper methods that generate the html for the pagination, I used this for kaminari and for will_paginate you should be able to use the will_paginate-bootstrap gem.Swipe
F
7

It is pretty easy to implement twitter bootstrap pagination with Kaminari. Just follow the steps below:

  1. Add gem 'kaminari' to your GemFile. Run bundle install and restart rails server
  2. Check the Kaminary themes - in your case you need the bootstrap3 theme
  3. Run rails g kaminari:views bootstrap3

That's it.

Flummery answered 12/9, 2014 at 21:26 Comment(1)
Thank you! rails g kaminari:views bootstrap4 worked for me just now.Selfinsurance
P
2

Kaminari works fine for me with Rails 4.1.5

You can get it working with Bootstrap 3 by changing one line of code in the generated Bootstrap theme for Kaminari

In Views/Kaminari/_paginator.html.erb

Change this line: <div class="pagination"><ul>

To this: <ul class="pagination pagination-lg">

..and get rid of the div; just use the ul above --works fine for me.


Here is the code for the whole partial:

  <%= paginator.render do %>
  <ul class="pagination pagination-lg">
    <%= first_page_tag unless current_page.first? %>
    <%= prev_page_tag unless current_page.first? %>
    <% each_page do |page| %>
      <% if page.left_outer? || page.right_outer? || page.inside_window? %>
        <%= page_tag page %>
      <% elsif !page.was_truncated? %>
        <%= gap_tag %>
      <% end %>
    <% end %>
    <%= next_page_tag unless current_page.last? %>
    <%= last_page_tag unless current_page.last? %>
  </ul>
<% end %>
Postcard answered 9/9, 2014 at 3:54 Comment(1)
Just implemented this just over 3 years later and still works perfectly.Gradatim

© 2022 - 2024 — McMap. All rights reserved.