Pagination undefined method `total_pages'

173 views
Skip to first unread message

GA Gorter

unread,
Jun 22, 2008, 4:54:26 PM6/22/08
to rubyonra...@googlegroups.com
I tried to use the gem will_paginate but it doesn't work as describs in
manual

Controller

def index
@sites = Site.paginate :per_page => 10, :page => params[:page]
end


View

<% for @sites in @sites %>
<%= @sites.naam %>
<%= will_paginate @sites %>
<% end %>

Also i set require 'will_paginate' below into the envoirment.rb

Is there a way to get will_paginate working well or is there a better
solution.
--
Posted via http://www.ruby-forum.com/.

Robby Russell

unread,
Jun 22, 2008, 5:33:26 PM6/22/08
to rubyonra...@googlegroups.com

I'm guessing that you left off ':all' in your code.

try this:

@sites = Site.paginate( :all, :per_page => 10, :page => params[:page] )

Good luck!

Cheers,
Robby

--
Robby Russell
Chief Evangelist, Partner

PLANET ARGON, LLC
design // development // hosting

http://www.planetargon.com/
http://www.robbyonrails.com/
aim: planetargon

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4068 [fax]

GA Gorter

unread,
Jun 22, 2008, 5:42:30 PM6/22/08
to rubyonra...@googlegroups.com
That makes no difference

Frederick Cheung

unread,
Jun 22, 2008, 5:47:14 PM6/22/08
to Ruby on Rails: Talk


On Jun 22, 9:54 pm, GA Gorter <rails-mailing-l...@andreas-s.net>
wrote:
> <% for @sites in @sites %>
> <%= @sites.naam %>
> <%= will_paginate @sites %>
> <% end %>

that's going to balls everything up: initially @sites is a
will_paginate collection, but then you're overwriting it with a single
element from that collection. Also do you really want to be rendering
the pagination links for each elements. Typically you would do
someting like
for sites in @sites ... (or use a partial, or @sites.each do |
site| ...)

Fred

GA Gorter

unread,
Jun 22, 2008, 8:11:14 PM6/22/08
to rubyonra...@googlegroups.com
I wrote it exactly as in the railscasts

http://railscasts.com/episodes/51

and the official manual

http://rock.errtheblog.com/will_paginate

even the require 'will_paginate' i did
Only without any result

Xavier Noria

unread,
Jun 22, 2008, 9:46:02 PM6/22/08
to rubyonra...@googlegroups.com
But are you using "for @sites in @sites" or not?

BTW, just in case, total_pages was recently added, it was called
page_count before.

GA Gorter

unread,
Jun 23, 2008, 2:56:24 AM6/23/08
to rubyonra...@googlegroups.com

Yes i'am using @sites for @sites

when i'am using something different i got the same issue

How can i fix total_pages the error contains into the gem

Frederick Cheung

unread,
Jun 23, 2008, 3:02:10 AM6/23/08
to Ruby on Rails: Talk


On Jun 23, 7:56 am, GA Gorter <rails-mailing-l...@andreas-s.net>
wrote:
> Xavier Noria wrote:
> > But are you using "for @sites in @sites" or not?
>
> > BTW, just in case, total_pages was recently added, it was called
> > page_count before.
>
> Yes i'am using @sites for @sites
>
> when i'am using something different i got the same issue
>
You're not using it as in the examples. THe examples all go
for site in @sites
#do something with site
end

will_paginate @sites

The way you do it can't work because you are reassigning one of the
sites to @sites, but will_paginate wants you to pass a collection, not
an individual element.


Fred

CJ

unread,
Jun 23, 2008, 5:32:10 AM6/23/08
to Ruby on Rails: Talk
BEtter use paginate_find and faster pagination in rails using the
below link
http://www.igvita.com/2006/09/10/faster-pagination-in-rails/

Its better and effective.


On Jun 23, 12:02 pm, Frederick Cheung <frederick.che...@gmail.com>
wrote:
> OnJun 23, 7:56 am, GA Gorter <rails-mailing-l...@andreas-s.net>
Reply all
Reply to author
Forward
0 new messages