Skip to content
An easy way to paginate a list of ActiveRecord objects alphabetically by any given attribute.
Ruby
Find file
Failed to load latest commit information.
lib
spec Add tests for current letter highlighting Oct 29, 2012
.document Initial commit to paginate_alphabetically. Aug 25, 2010
.gitignore I shall need Jeweler gem in order to release this. Dec 23, 2010
Gemfile Switch to bundler for gem releasing Nov 11, 2012
Gemfile.lock
LICENSE
README.textile Added show_all_letters option to skip slow letter finding code Dec 22, 2010
Rakefile
VERSION Fixed version params Nov 11, 2012
install.rb Add plugin files into this gem. Aug 25, 2010
paginate_alphabetically.gemspec Fixed version params Nov 11, 2012
uninstall.rb Add plugin files into this gem. Aug 25, 2010

README.textile

PaginateAlphabetically

An easy way to paginate a list of ActiveRecord objects alphabetically by any given attribute.

Example

Model

class User < ActiveRecord::Base
  paginate_alphabetically :by => :surname
end

Controller

class UsersController < ApplicationController
  def index
    @users = User.alphabetical_group(params[:letter])
  end
end

View (haml example)

= alphabetically_paginate(@users)
%ul.users
  - @users.each do |user|
    %li= user.surname

Testing

The tests use a sqlite3 in-memory database to be able to run separately from your application.

rake test

Options

The initial model code will take a show_all_letters option, in order to skip the (slow) letter finding code:

class User < ActiveRecord::Base
  paginate_alphabetically :by => :surname, :show_all_letters => true
end

Thanks to hoverlover the alphabetically_paginate view helper can take an options hash which allows you to override the class if you don’t want it to be ‘pagination’. For example:

= alphabetically_paginate(@users, :class => 'user-pagination')

Contributing

We welcome feedback, issues and especially pull requests. Please make sure your change is tested. Please do not update the VERSION file – we’ll do that automatically. Thanks!

Copyright © 2010 Eden Development, released under the MIT license

Something went wrong with that request. Please try again.