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

has_paginate

other solution to will_paginate:
http://rdoc.info/projects/fnando/has_paginate

can used named scopes introduced in rails 2.1 http://mattpayne.ca/blog/post/named-scope

Taggings:

Pagination via Paged Scope

A relatively new alternative to the omnipresent will_paginate is the paged scopes gem at http://github.com/mholling/paged_scopes

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: http://code.matthewhollingworth.net/articles/2009-06-28-paged-scopes-a-w...
Part II: http://code.matthewhollingworth.net/articles/2009-06-30-paged-scopes-par...
Part III: http://code.matthewhollingworth.net/articles/2009-07-02-paged-scopes-par...

Installation instructions:
gem sources -a http://gemcutter.org
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 => "http://gemcutter.org"
config.gem "subdomain_routes", :source => "http://gemcutter.org"
config.gem "paged_scopes", :source => "http://gemcutter.org"

Taggings:

will_paginate

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

will_paginate

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 http://gems.github.com

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”

Rails::Initializer.run do |config|
...
end

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:
http://github.com/mislav/will_paginate/wikis

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

Happy Hacking!!!

Taggings: