# Will\_paginate: pagination links are wrong

**URL:** <https://www.ruby-forum.com/t/will-paginate-pagination-links-are-wrong/174302>\
**Category:** Rails\
**Created:** [August 24, 2009, 8:20pm UTC](https://www.ruby-forum.com/t/will-paginate-pagination-links-are-wrong/174302 "2009-08-24T20:20:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 24, 2009, 8:20pm UTC](https://www.ruby-forum.com/t/will-paginate-pagination-links-are-wrong/174302/1 "2009-08-24T20:20:28Z")

</div>

I put everything in a pastie to make it a bit more readable:  
[http://pastie.org/593379](http://pastie.org/593379)

This is the gist:

Will\_paginate doesn’t play quite nice. The first result set is fine,  
and when I click on one of the paginated links, it returns the following  
error:  
Couldn’t find DictatedExam with ID=filter\_widget  
observe\_field triggers filter\_widget which calls the paginated search…  
Which is then rendered in a partial.

Why do things simple when you can do it complicated, right ?

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 24, 2009, 8:36pm UTC](https://www.ruby-forum.com/t/will-paginate-pagination-links-are-wrong/174302/2 "2009-08-24T20:36:55Z")

</div>

Addendum:

This is what the links look like.  
I have no idea what they’re -supposed- to look like.

[http://localhost:3000/dictated\_exams/filter\_widget?page=4](http://localhost:3000/dictated_exams/filter_widget?page=4)

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 24, 2009, 8:59pm UTC](https://www.ruby-forum.com/t/will-paginate-pagination-links-are-wrong/174302/3 "2009-08-24T20:59:21Z")

</div>

Aldric G. wrote:

> Addendum:
> 
> This is what the links look like.  
> I have no idea what they’re -supposed- to look like.
> 
> [http://localhost:3000/dictated\_exams/filter\_widget?page=4](http://localhost:3000/dictated_exams/filter_widget?page=4)

Okay… I figured this bit out:

Processing DictatedExamsController#show (for 127.0.0.1 t 2009-08-24  
14:54:09) [GET]  
Parameters: {“id”=\>“filter\_widget”, “page”=\>“2”}  
DictatedExm Load (15.0ms) SELECT \* FROM “dictated\_exms” WHERE  
(“dictated\_exms”.“id” = 0)

ActiveRecord::RecordNotFound (Couldn’t find DictatedExam with  
ID=filter\_widget):  
pp/controllers/dictated\_exams\_controller.rb:16:in `show’

So I’m giving the id of ‘filter\_widget’… Why ?

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 25, 2009, 4:16pm UTC](https://www.ruby-forum.com/t/will-paginate-pagination-links-are-wrong/174302/4 "2009-08-25T16:16:01Z")

</div>

AND FIXED!  
I followed [http://jellofishi.com/blog/?cat=3](http://jellofishi.com/blog/?cat=3)

I created app/helpers/remote\_link\_renderer.rb

class RemoteLinkRenderer \< WillPaginate::LinkRenderer  
def prepare(collection, options, template)  
@remote = options.delete(:remote) || {}  
super  
end

protected  
def page\_link(page, text, attributes = {})  
@template.link\_to\_remote(text, {:url =\> url\_for(page), :method =\>  
:post}.merge(@remote))  
end  
end

And then in the environment.rb I added, after the Initializer block:

require “will\_paginate”  
WillPaginate::ViewHelpers.pagination\_options[:renderer] =  
‘RemoteLinkRenderer’

My will\_paginate has become:  
\<%= will\_paginate dictated\_exams, :params =\> {:date =\> date },  
:remote =\> { :update =\> ‘filter\_counts’} %\>

And now it all works…

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 24, 2009, 9:42pm UTC](https://www.ruby-forum.com/t/will-paginate-pagination-links-are-wrong/174302/5 "2009-08-24T21:42:35Z")

</div>

Okay! I got the pagination links to work. Now I need them to display in  
the same div where the first results go, without reloading a page and  
discarding my layout.

I had to:  
ROUTES.RB  
map.resources :dictated\_exams, :collection =\> {:filter\_widget =\> :get}

\_list.erb:  
\<%= will\_paginate dictated\_exams, :params =\> {:date =\> date} %\>

index.html.erb, the observe\_field:  
:url =\> {:action =\> ‘filter\_widget’, :controller =\> ‘dictated\_exams’,  
:method =\> :post },

dictated\_exams\_controller.rb:  
def filter\_widget  
@date ||= params[:date].to\_date  
end\_date = @date + 1.days  
dictated\_exams = DictatedExam.search\_one\_day(@date, params[:page])  
render :partial =\> ‘dictated\_exams/list’ , :locals =\>  
{ :dictated\_exams =\> dictated\_exams, :date =\> @date }  
end

Now to get the results to display where I want them to display…
