Kaminari-Cells Is Ready!

The kaminari gem is a project to simplify pagination – often used in Rails apps. Cells provides view components for Rails. Those two just got married and their child is called kaminari-cells. Yay!!!

Kami..what?

Kaminari adds pagination logic to finders – it works with all kinds of ORMs, e.g. in ActiveRecord. It also gives us a bunch of helpers to render pagination links.

It is extremely popular as it doesn’t pollute objects with pagination logic.

Typically, a controller, an operation or a model will accumulate models to display.

@users = User.order(:name).page params[:page]

Later, in a view, after rendering the rows itself you want to display a link to jump to the next or previous page.

= paginate @users

A really simple and cool thing.

Pagination In Cells.

As kaminari uses global partials to render the pagination links, we had to make it work with cells, which usually does not use global partials. Thanks to the fine kaminari team, this was implemented, tested and merged within hours.

All you need to do to make the paginate helper work in a cell view is add the gem to your Gemfile.

gem "kaminari-cells"

And then extend the class.

class CommentsCell < Cell::Rails
  include Kaminari::Cells

This works for both conventional cells and view models.

Advertisements

One thought on “Kaminari-Cells Is Ready!

  1. Awesomeness! I’ve been waiting to ditch the will_paginate gem for a long, long time. Kaminari is great because it allows paginating arrays, not just model collections. Thanks!!! ❤ ❤ ❤

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s