Ruby On Rails Pagination

Hi TU Techies! I´m currently working on my first Ruby On Rails applikation. A part of this app is an adress-management userinterface. As the app manages a great amount of adresses there is a search page in the app. I want to display the search results with a google like pagintor. But I don´t really how. Pleas help me!
3 answers


other solution to will_paginate:

can used named scopes introduced in rails 2.1


Pagination via Paged Scope

A relatively new alternative to the omnipresent will_paginate is the paged scopes gem at

I just link to the following 3 blog posts by the author which sum up pretty much all of the advantages and uses of this gem.

Part I:
Part II:
Part III:

Installation instructions:
gem sources -a
sudo gem install active_url
sudo gem install subdomain_routes
sudo gem install paged_scopes

And in the environment.rb file for a Rails project:
config.gem "active_url", :source => ""
config.gem "subdomain_routes", :source => ""
config.gem "paged_scopes", :source => ""



I recently had the same problem and found really fancy plugin:


The plugin can be installed like so:

First, ensure that you’re running at least RubyGems 1.2 (check gem -v if you’re not sure).

The will_paginate gem is built by GitHub. Add GitHub to your gem sources (once per machine):

gem sources -a

Install the library:

gem install mislav-will_paginate

To enable the library your Rails 2.0.x (or even 1.2.x) project, load it in “config/environment.rb” do |config|

require "will_paginate"

Don’t put it before or inside the Rails::Initializer block because the Rails framework is not yet loaded at that point of execution.

That will always load the latest installed version of the gem. If you want to have control of the version loaded, you can use version constraints with the gem method:

# choose one of the following constraints:
gem 'mislav-will_paginate', '2.1.0'
gem 'mislav-will_paginate', '>=2.1.0'
gem 'mislav-will_paginate', '~>2.1' # this will load any 2.x version
# (greater or equal to 2.1), but not 3.x

# finally, load the library
require 'will_paginate'

Puhhh, that was the hard part know look how cool it works:

It’s very easy to do pagination on ActiveRecord models:

@posts = Post.paginate :page => params[:page], :order => 'created_at DESC'

In the view, page links can be rendered with a single view helper:

<%= will_paginate @posts %>

For further information:

and if that´s not enough: google is your friend

Happy Hacking!!!