WordPress database error Can't create/write to file '/tmp/#sql_e94_0.MYI' (Errcode: 28) for query SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'post_tag') AND tr.object_id IN (476) ORDER BY t.name ASC made by require, wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, update_post_caches, update_object_term_cache, wp_get_object_terms WordPress database error Can't create/write to file '/tmp/#sql_e94_0.MYI' (Errcode: 28) for query SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'post_tag') AND tr.object_id IN (138) ORDER BY t.name ASC made by require, require_once, include, get_header, locate_template, load_template, require_once, wp_head, do_action, call_user_func_array, start_post_rel_link, get_boundary_post_rel_link, get_boundary_post, get_posts, WP_Query->query, WP_Query->get_posts, update_post_caches, update_object_term_cache, wp_get_object_terms
dimas priyanto a guy with mouse and keyboard

Using Kaminari to paginate Array

Written on October 28, 2011

Pagination sounds very popular for us, when building some admin pages or user pages that renders many items, we usually use it to make it more user friendly and “computer friendly”, In practice of Active Record usage, i previously used will_paginate to deal with, but now I changed my mind to use more friendly pagination for Active Record. I might say it has one more friendliness, “programmer friendly”. As the creator said it doesn’t pollute AR::Base, Array or Hash and it supporting other ORM (it actually ODM, Mongoid).

One thing i wanna share is, that sometimes we need to paginate collection that is an instance of Array class. Lately i use Mongoid for my several projects and Kaminari is a good choice. I can perform selection to a class using Model.page(params[:page]).per(10), that’s very friendly syntax, i love it.

And dealing with document database is not reliable as SQL for complex query on association, referencing document to other document is not a good thing when we need to perform sorting and ordering by field that exists on the referenced document. As my system design should use reference relation not embedded stuff, so i got the problem.

The solution is fetch the objects we wanted from the class using regular finder method, sort and order it using criteria we wanted, then convert it to array and use the magic:

Kaminari.paginate_array(@my_array)

when we call it using paginate @my_array on the views it will act like we use regular kaminari in the controller, will_paginate has also this feature, but it’s been too long not using will_paginate. Correct me if i’m wrong and hope this helps..