Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 pagination, will_paginate vs. Kaminari using with bootstrap3

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?

like image 250
tkymtk Avatar asked Jan 29 '14 08:01

tkymtk


3 Answers

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!

like image 55
Richard Peck Avatar answered Nov 01 '22 03:11

Richard Peck


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.

like image 26
gotqn Avatar answered Nov 01 '22 03:11

gotqn


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 %>
like image 2
Jordan Avatar answered Nov 01 '22 04:11

Jordan