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
...
end
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:
0xc8ec7e>
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!
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 }
end
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.
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
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.
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.......
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
error.
So I think the position of <%= will_paginate @posts %> in view file
should be problem.
I'm currently using NetBeans as an editor only It can do almost
everything like textmate/E but it's free (no cash to buy E so far,
saving money for MacBook Air :-))
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 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
~/.netbeans/6.1/jruby-1.1/lib/ruby/gems/1.8/gems/will_paginate-2.2.2/
lib/will_paginate/
and making the method "def url_for(page)" public by moving it above
the "protected" statement.