Skip to content

Instantly share code, notes, and snippets.

@Gedrovits
Created December 30, 2013 11:11
Show Gist options
  • Save Gedrovits/8180789 to your computer and use it in GitHub Desktop.
Save Gedrovits/8180789 to your computer and use it in GitHub Desktop.
Kaminari-powered shared paginator
-# shared/_index.js.haml
:plain
$("##{escape_javascript models.first.class.name.tableize.dasherize}").html("#{escape_javascript render(models)}");
$('#pager').html("#{escape_javascript(paginate(models, remote: true).to_s)}#{escape_javascript(page_entries_info models)}");
-# shared/_pager.html.haml
- remote = remote ? remote : false
#pager.centered
= paginate models, remote: remote
= page_entries_info models
# Controller action example
class ExamplesController < ApplicationController
def index
@examples = Example.page params[:page]
respond_to do |format|
format.html #index.html.haml
format.json { render json: @examples }
format.js { render partial: 'shared/index', locals: { models: @examples } }
end
end
end
-# examples/index.html.haml
%table#examples.custom.table.table-bordered.table-striped.table-condensed
%thead
%tr
%th One
%th Two
%th Three
%tbody
= render @examples
= render 'shared/pager', models: @examples, locals: { remote: true }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment