This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Sat Oct 31 08:32:13 -0700 2009 | |
| |
MIT-LICENSE | Fri Oct 23 06:59:42 -0700 2009 | |
| |
README.md | Mon Nov 02 14:09:00 -0800 2009 | |
| |
Rakefile | Sat Oct 31 11:31:15 -0700 2009 | |
| |
assets/ | Sat Oct 31 13:46:48 -0700 2009 | |
| |
init.rb | Sat Oct 31 07:17:35 -0700 2009 | |
| |
install.rb | Sat Oct 31 09:31:48 -0700 2009 | |
| |
lib/ | Fri Dec 04 06:19:58 -0800 2009 | |
| |
spec/ | Fri Dec 04 06:19:58 -0800 2009 | |
| |
tasks/ | Sat Oct 31 11:31:15 -0700 2009 | |
| |
uninstall.rb | Sat Oct 31 09:31:48 -0700 2009 |
README.md
more_paginate
Twitter like pagination for Rails.
Basic usage
more_paginate provides a class and associations level method for paginate your records:
Tweet.paginate :all
person.tweets.paginate :all
It's just a tiny enforcement for ActiveRecord::Base#find and it accepts the following additional params:
sort_keysort_valuesort_idsort_order(optional)
Example
For a full working example, please visit more_paginate_example repository.
# app/models/tweet.rb
class Tweet < ActiveRecord::Base
belongs_to :person
def self.paginate_by_creation_date(params)
paginate :all,
:sort_key => params[:sort_key] || "created_at",
:sort_value => params[:sort_value],
:sort_id => params[:sort_id],
:sort_order => "desc",
:include => :person
end
end
# app/controllers/tweets_controller.rb
class TweetsController < ApplicationController
def index
@tweets = Tweet.paginate_by_creation_date params.dup
respond_to do |format|
format.html
format.js { render :partial => "tweet_list" }
end
end
end
# app/views/tweets/index.html.erb
<h1>Tweets</h1>
<div id="tweets">
<%= render "tweet_list" %>
</div>
# app/views/tweets/_tweet_list.html.erb
<ol class="tweetList">
<% @tweets.each do |tweet| -%>
<li class="tweet">
<%= avatar tweet.person %>
<%= link_to h(tweet.person.nickname), person_path(tweet.person), :class => "bold" %>
<%= truncate h(tweet.text), :length => 140 %><br />
<span class="time"><%= link_to tweet.created_at.to_s(:db), tweet_path(tweet) %></span>
</li>
<% end -%>
<ol>
<%= more_paginate @tweets %>
# public/javascripts/application.js
$(document).ready(function() {
$("#more_link").morePaginate({ container: "#tweets" });
});
Acknowledgements
- @lifo for his great speech about Lessons learnt and pagination.
- @deadroxy for her help.
- The Yahoo! team for their awesome Efficient Pagination Using MySQL presentation.
Copyright
Copyright (c) 2009 Luca Guidi, released under the MIT license.







