Pagination undefined method `total_pages'

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.

On Sun, Jun 22, 2008 at 1:54 PM, GA Gorter
[email protected] wrote:

solution.
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 R.
Chief Evangelist, Partner

PLANET ARGON, LLC
design // development // hosting

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

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

That makes no difference

I wrote it exactly as in the railscasts

and the official manual

http://rock.errtheblog.com/will_paginate

even the require ‘will_paginate’ i did
Only without any result

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.

Xavier N. 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

How can i fix total_pages the error contains into the gem

On Jun 22, 9:54 pm, GA Gorter [email protected]
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

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 C. [email protected]

On Jun 23, 7:56 am, GA Gorter [email protected]
wrote:

Xavier N. 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