# Custom pagination

**URL:** <https://www.ruby-forum.com/t/custom-pagination/123507>\
**Category:** Rails\
**Created:** [December 18, 2007, 10:15am UTC](https://www.ruby-forum.com/t/custom-pagination/123507 "2007-12-18T10:15:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [December 18, 2007, 10:15am UTC](https://www.ruby-forum.com/t/custom-pagination/123507/1 "2007-12-18T10:15:20Z")

</div>

In ci\_controller i wrote

def search\_ci  
page = (params[:page] ||= 1).to\_i  
software\_cis\_per\_page = 3  
offset = (page - 1) \* software\_cis\_per\_page  
@software\_cis = SoftwareCi.find\_by\_sql([“select \* from software\_cis  
where name like ? and status like ? and citype like ? and ci\_class like  
?”, “%” + params[:ci][:name] + “%”, “%” + params[:ci][:status] + “%”,  
“%” + params[:ci][:citype] + “%”, “%” + params[:ci][:ci\_class] + “%” ])  
@software\_ci\_pages = Paginator.new(self, @software\_cis.length,  
software\_cis\_per\_page, page)  
@software\_cis = @software\_cis[offset…(offset + software\_cis\_per\_page -  
1)]  
end

and in the view search\_ci.rhtml,

\<%= link\_to(‘previous page’, {:params =\> params.merge(‘page’ =\>  
@software\_ci\_pages.current.previous)}) if  
@software\_ci\_pages.current.previous %\>  
\<%= ’ | ’ if @software\_ci\_pages.current.previous and  
@software\_ci\_pages.current.next %\>  
\<%= link\_to(‘next page’, {:params =\> params.merge(‘page’ =\>  
@software\_ci\_pages.current.next)}) if @software\_ci\_pages.current.next %\>

The first page is displayed. But when we click on the ‘next page’ an  
error occurs… “can’t convert nil into String”

I printed the value in ‘page’ variable. It is 1 always.

any idea on how to fix this error.

---

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [December 18, 2007, 11:34am UTC](https://www.ruby-forum.com/t/custom-pagination/123507/2 "2007-12-18T11:34:39Z")

</div>

On 18 Dec 2007, at 09:15, Suneeta Km wrote:

> The first page is displayed. But when we click on the ‘next page’ an  
> error occurs… “can’t convert nil into String”
> 
> I printed the value in ‘page’ variable. It is 1 always.

I rather suspect that you want link\_to(‘next page’,  
params.merge(‘page’ =\> @software\_ci\_pages.current.next))  
Looking at what rails thinks the params hash is should guide you on  
your way

Fred

---

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [December 18, 2007, 12:08pm UTC](https://www.ruby-forum.com/t/custom-pagination/123507/3 "2007-12-18T12:08:41Z")

</div>

Frederick C. wrote:

> On 18 Dec 2007, at 09:15, Suneeta Km wrote:
> 
> > The first page is displayed. But when we click on the ‘next page’ an  
> > error occurs… “can’t convert nil into String”
> > 
> > I printed the value in ‘page’ variable. It is 1 always.
> 
> I rather suspect that you want link\_to(‘next page’,  
> params.merge(‘page’ =\> @software\_ci\_pages.current.next))  
> Looking at what rails thinks the params hash is should guide you on  
> your way
> 
> Fred

@software\_cis has only the first 3 rows which is to be displayed in the  
first page. But i’m not able to display the remaining rows in the next  
page. Please suggest a solution to this.
