How to accomplish pagination in RoR

Hi Folks,

I am just trying to get started up in RoR, I have done a simple
application of add, edit, delete…

I am now trying to accomplish pagination in RoR, I referred a few

tutorials, however none of the examples that i tried from there,
seemed to work error free… I have heard that lots of things have
deprecated in RoR, can someone please post me a detailed report of how
i can setup a pager in RoR, i mean the most straightforward and simple
way to do it…

I am using ruby 1.8.6

Looking forward to help from all u guys…

Thanks and Regards,
Durgesh.

Try will_paginate, and you’ll love it.

Hi,

You can generate scaffolding for a model (ruby script/generate scaffold
) and examine the resulting code - it should contain support
for pagination. Be careful so you don’t tell it to overwrite any files
you care about!

Cheers

previous versions of rails < 2.x the pegination was built in with the
classic pegination. but with rails2.0 it removed from the rails core.
You need to look at the classic peginatior which is a built in for
rails 1.8.x. or you can use a plugin like will_peginator

We are using will_paginate in the Rails 2 version of our
BuildingWebApps.com site. I like it a lot better than the classic
version. This article, starting halfway down got us going pretty well:

http://nasir.wordpress.com/2007/10/31/pagination-in-ruby-on-rails-using-will_paginate-plugin/

-Christopher

i was trying to install will_paginate, however i do not have svn on my
machine…i tried the following commands:
ruby script/plugin
install svn://errtheblog.com/svn/plugins/will_paginate

can anyone please tell me how i can install the will_paginate plugin
without svn?

i get the following error:

ERROR: while executing gem … Gem::RemoteFetcher::FetchError
A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection
failed because connected host has failed to respond. -connect<2>
Errno::ETIMEDOUT
getting size of http://gems.rubyforge.org/Marshal.4.8

On Apr 17, 10:14 am, Phillip G. [email protected]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

durgesh wrote:
| i was trying to install will_paginate, however i do not have svn on my
| machine…i tried the following commands:
| ruby script/plugin
| install svn://errtheblog.com/svn/plugins/will_paginate
|
| can anyone please tell me how i can install the will_paginate plugin
| without svn?

PS C:\Documents and Settings\CynicalRyan> gem search will_paginate -r

*** REMOTE GEMS ***

Updating metadata for 27 gems from http://gems.rubyforge.org/

complete
will_paginate (2.2.1)


Phillip G.
Twitter: twitter.com/cynicalryan

~ - You know you’ve been hacking too long when…
…you start reading car license plates as machine code. JMP 451, HCF
919
(this one really shook me up), HLT 772 (Halt instruction…gotta reboot
the
truck again!), FOXXY (um, don’t know that one…must be a floating point
instruction).
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgHFPIACgkQbtAgaoJTgL/yRgCdGsnUit0VmcYCpn6oOlWMws83
B9kAn3c36Wy1K7v3r3pgK++9YQdJ3gDB
=wKpj
-----END PGP SIGNATURE-----

ok i got the will_paginate gem to sucessfully installe: now when i try
to use the pagination i get the following error in the browser:

NoMethodError in PeopleController#index
undefined method `paginate’ for Person(id: integer, name: string,
address: text):Class
RAILS_ROOT: C:/ruby/contact

Application Trace | Framework Trace | Full Trace
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
base.rb:1532:in method_missing' app/models/person.rb:7:insearch’
app/controllers/people_controller.rb:5:in `index’

this is the pagination code in controller:
def index
@people = Person.search(params[:search], params[:page])
end

this is the code in the model i.e person.rb
def self.search(search, page)
paginate :per_page => 5, :page => page,
:conditions => [‘name like ?’, “%#{search}%”],
:order => ‘name’
end

and this is the code in the index.html.erb:

Listing people

<% for person in @people %>

<% end %>
Name Address
<%=h person.name %> <%=h person.address %> <%= link_to 'Show', person %> <%= link_to 'Edit', edit_person_path(person) %> <%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete %>

<%= will_paginate @people %>

<%= link_to ‘New person’, new_person_path %>

Guys, does anyone know what mistake i might have made?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

durgesh wrote:
| ok i got the will_paginate gem to sucessfully installe: now when i try
| to use the pagination i get the following error in the browser:

Don’t you think that actively looking for will_paginate’s documentation
might help?

That approach turned up the following site:
http://github.com/mislav/will_paginate/wikis/installation

Which, oddly enough, tells you how to use will_paginate.


Phillip G.
Twitter: twitter.com/cynicalryan

~ “I suppose if we couldn’t laugh at things that don’t make sense, we
couldn’t react to a lot of life.” -Hobbes
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgHO6sACgkQbtAgaoJTgL+5igCgiVfiVufrn1VkAzL1ij9o9l9Q
s+oAoJzbyjZDbhEua1oRhPiohlH3GJdm
=oKad
-----END PGP SIGNATURE-----

friends, thanks a lot for all the help offererd so far…however, i
am getting the same error, even after following the instructions:

undefined method `paginate’ for Person(id: integer, name: string,
address: text):Class
RAILS_ROOT: C:/ruby/contact

Application Trace | Framework Trace | Full Trace
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
base.rb:1532:in method_missing' app/models/person.rb:7:insearch’
app/controllers/people_controller.rb:5:in `index’

this is the pagination code in controller:
def index
@people = Person.search(params[:search], params[:page])
end

this is the code in the model i.e person.rb
def self.search(search, page)
paginate :per_page => 5, :page => page,
:conditions => [‘name like ?’, “%#{search}%”],
:order => ‘name’
end

and this is the code in the index.html.erb:

Listing people

<% for person in @people %>

<% end %>
Name Address
<%=h person.name %> <%=h person.address %> <%= link_to 'Show', person %> <%= link_to 'Edit', edit_person_path(person) %> <%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete %>

<%= will_paginate @people %>

<%= link_to ‘New person’, new_person_path %>

Guys, does anyone know what mistake i might have made? please do
help

On Apr 17, 12:59 pm, Phillip G. [email protected]

On 17 Apr 2008, at 14:14, durgesh wrote:

friends, thanks a lot for all the help offererd so far…however, i
am getting the same error, even after following the instructions:

Did you add the require ‘will_paginate’ in your environment, like it
says in the docs ?

Fred

oh buddies, really very thankful to all of u…the problem was coming
becoz i did not restart the webrick server after pasting the lines
into the config/environment.rb…after i did that…things worked!!

thanks once again to all of u…looking forward to your help in
future too… :slight_smile:

On Apr 17, 3:07 pm, Frederick C. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs