# Mislav-will\_paginate(will\_paginate)

**URL:** <https://www.ruby-forum.com/t/mislav-will-paginate-will-paginate/178071>\
**Category:** Rails\
**Created:** [October 28, 2009, 6:34pm UTC](https://www.ruby-forum.com/t/mislav-will-paginate-will-paginate/178071 "2009-10-28T18:34:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![duke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e8c25b/32.png) [@duke](https://www.ruby-forum.com/u/duke)\
**Post date:** [October 28, 2009, 6:34pm UTC](https://www.ruby-forum.com/t/mislav-will-paginate-will-paginate/178071/1 "2009-10-28T18:34:00Z")

</div>

mislav-will\_paginate(will\_paginate) doesn’t work after search.

servers\_controller.rb  
def index  
@servers = Server.paginate(:page =\> params[:page], :per\_page =\> 20,  
:order =\> ‘device\_id ASC’)  
respond\_to do |format|  
format.html # index.html.erb  
format.xml { render :xml =\> @servers }  
end  
end

def search  
@servers = Server.paginate(:page =\> params[:page], :per\_page =\>  
20, :order =\> ‘device\_id ASC’, :conditions =\> [“hostname like ?”,  
“%”+params[:keyword]+"%"])  
render :action =\> ‘index’  
end

index.html.erb  
\<%= will\_paginate @servers %\>

paginate works fine for index, but after search, only first page is  
showed,  
when I click “next” or “2”, the error appears.  
ActiveRecord::RecordNotFound (Couldn’t find Server with ID=search):  
app/controllers/servers\_controller.rb:26:in `show’

It seems like paginate doesn’t know, params[:keyword],  
I haven’t done anything for “def show” in servers\_controller.rb.

def show  
@server = Server.find(params[:id])

```
respond_to do |format|
  format.html # show.html.erb
  format.xml { render :xml => @server }
end

```

end

How can I resolve this issue?

-duke

---

<div class="post-metadata">

**Author:** ![duke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e8c25b/32.png) [@duke](https://www.ruby-forum.com/u/duke)\
**Post date:** [October 28, 2009, 7:00pm UTC](https://www.ruby-forum.com/t/mislav-will-paginate-will-paginate/178071/2 "2009-10-28T19:00:57Z")

</div>

Quoting Duke Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):  
[snip]

> paginate works fine for index, but after search, only first page is  
> showed,  
> when I click “next” or “2”, the error appears.  
> ActiveRecord::RecordNotFound (Couldn’t find Server with ID=search):  
> app/controllers/servers\_controller.rb:26:in `show’

[snip]

Check your routing and URLs. I suspect they don’t match for search.

HTH,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![duke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e8c25b/32.png) [@duke](https://www.ruby-forum.com/u/duke)\
**Post date:** [October 28, 2009, 8:58pm UTC](https://www.ruby-forum.com/t/mislav-will-paginate-will-paginate/178071/3 "2009-10-28T20:58:49Z")

</div>

Jeffrey L. Taylor wrote:

> Quoting Duke Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):  
> [snip]
> 
> > paginate works fine for index, but after search, only first page is  
> > showed,  
> > when I click “next” or “2”, the error appears.  
> > ActiveRecord::RecordNotFound (Couldn’t find Server with ID=search):  
> > app/controllers/servers\_controller.rb:26:in `show’
> 
> [snip]
> 
> Check your routing and URLs. I suspect they don’t match for search.
> 
> HTH,  
> Jeffrey

I added it to routes.rb  
map.search ‘/search’, :controller =\> ‘servers’, :action =\> ‘search’  
But I receive different error at this time,  
TypeError in ServersController#search  
can’t convert nil into String

It seems like paginate doesn’t no what keyword has been used for search  
on next page,  
so I changed view from \<%= will\_paginate @servers %\> to  
\<%= will\_paginate @servers, :params =\> {:keyword =\>params[:keyword]} %\>

“:params =\> {:keyword =\>params[:keyword]}” this part is hand the  
parameter to the next page.

What I have done is created search.html.erb instead of using  
index.html.erb,  
the only difference between search and index is  
“:params =\> {:keyword =\>params[:keyword]}”

and added routes.rb, and modified “def search” in servers\_controller.rb  
respond\_to do |format|  
format.html # index.html.erb  
format.xml { render :xml =\> @servers }  
end

instead of  
render :action =\> ‘index’

It works fine now.  
Thank you Jeffrey.
