Occurred url_for ERROR mesasge while using will_paginate

Hi, I am trying pagination with using the plug-in: will_paginate.
Here is my code, I got a scaffold model named “post”.

in posts_controller.rb:
I insert the following code in the index method

def index

@posts = Post.paginate :page => params[:page], :per_page => 3


in posts/index.html.erb
I insert the the following code at the bottom of file

<%= will_paginate @posts %>

Then I run it, but got the following error message. What I missed??

NoMethodError in Posts#index

Showing posts/index.html.erb where line # raised:

protected method `url_for’ called for #<WillPaginate::LinkRenderer:

The will_paginate version of mine is: 2.2.1
I think to use the pagination mechanism provided by will_paginate
should be easy.
Could somebody give me a guide? Thanks!


Try this in your controller:

@posts = Post.paginate(:all, :page => params[:page], :per_page => 3)

The paginate method acts the same as find, so you usually will need to
specify either :all or :first.

If that doesn’t do it, paste your full error.


I try it, but it still doesn’t work.
Here is the full error trace log:

NoMethodError in Posts#index

Showing posts/index.html.erb where line # raised:

protected method `url_for’ called for #<WillPaginate::LinkRenderer:

Extracted source (around line #):

RAILS_ROOT: D:/InstantRails-2.0-win/rails_apps/ApmKm
Application Trace | Framework Trace | Full Trace

D:/NetBeans 6.1 RC1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
page_link_or_span' D:/NetBeans 6.1 RC1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ will_paginate-2.2.1/lib/will_paginate/view_helpers.rb:212:inwindowed_links’
D:/NetBeans 6.1 RC1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
will_paginate-2.2.1/lib/will_paginate/view_helpers.rb:209:in each' D:/NetBeans 6.1 RC1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ will_paginate-2.2.1/lib/will_paginate/view_helpers.rb:209:ininject’
D:/NetBeans 6.1 RC1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
windowed_links' D:/NetBeans 6.1 RC1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ will_paginate-2.2.1/lib/will_paginate/view_helpers.rb:175:into_html’
D:/NetBeans 6.1 RC1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
will_paginate' app/views/posts/index.html.erb:25:in_run_erb_47app47views47posts47index46html46erb’
app/controllers/posts_controller.rb:11:in index' :1:instart’

Is it really not giving you line numbers in the errors? What is on
line 25 of your index.html.erb? Line 11 in your controller?

It could be something strange regarding Instant Rails.


The line 25 of index.html.erb is:
<%= will_paginate @posts %>

And the line 11 of the controller should be:
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }

But If I remove the line 11 in the controller
The error still occurs. It’s really a strange error.
Maybe I miss some gems?
But I do install the will_paginate plug-in completely.

firestoke wrote:

The line 25 of index.html.erb is:
<%= will_paginate @posts %>


respond_to do |format|

format.html # index.html.erb

format.xml { render :xml => @posts }


here is to option for @posts:

[1] @posts = Post.paginate :page => params[:page], :per_page => 3
[2] @posts = paginate :posts, :page => params[:page], :per_page => 3

let me know what happen.


I have tons of trouble in implementing my rails application trough
NetBeans, so that I prefer to use RoRED, Instant Rails or SCITE to run
rails server than NetBean unless it’s only for editor.


ya, I mark it but result is the same.
After tried many times, I found this error only occurs when launch it
from Netbeans WEBrick(press F6 to run main project).
If I launch it by the Mongrel provided by Instant Rails, then it works
just fine!!
But I still don’t know what the root cause is, very strange and
mysterious… just like Titanic… Orz


hi im anas

to use will_paginate u have 2 install will_paginate gem…
and u wrote the code in controller is correct…
but in view(i.e. in index) we’ve to define <%= will_paginate @posts %>
in very first line…
i hope this will solve ur problem…

It’s a NetBeans bug, had the same problem.

just run the server from console, not from netbeans, and it should
work (did for me)

also managed to google out a patch
but haven’t tried it yet

I’m currently using NetBeans as an editor only :slight_smile: It can do almost
everything like textmate/E but it’s free (no cash to buy E so far,
saving money for MacBook Air :-))

On 02/06/2008, pepa007 [email protected] wrote:

It’s a NetBeans bug, had the same problem.

Actually I think it is a JRuby bug, not NetBeans. You can always use
native Ruby (MRI) in NetBeans instead of JRuby, just set the platform
to Ruby in your project properties (right click the project node →
properties → ruby platform). If you don’t see native Ruby listed
there you can add it by clicking the manage button next to the
platform combo box.

In any case the issue has been fixed in JRuby 1.1.2, which was
released a while ago.


I do install will_paginate gem both in Netbeans and Instant Rails.
(because they got their own ruby interpreter)
And the code I write at the first post is just fine. I didn’t change
them at all and just launch by Mongrel, then it works without any
So I think the position of <%= will_paginate @posts %> in view file
should be problem.


I stumbled on the same problem, and I’m using NetBeans (6.1), JRuby
(1.1), Rails (2.0.2) (etc, etc) as well.

The problem when away after editing the will_paginate view_helpers.rb
file, that (for me) lives in
and making the method “def url_for(page)” public by moving it above
the “protected” statement.

You have to restart the Webrick process.

Cheers, Birgit