# Changed to will\_paginate

**URL:** <https://www.ruby-forum.com/t/changed-to-will-paginate/138000>\
**Category:** Rails\
**Created:** [May 19, 2008, 11:49am UTC](https://www.ruby-forum.com/t/changed-to-will-paginate/138000 "2008-05-19T11:49:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 19, 2008, 11:49am UTC](https://www.ruby-forum.com/t/changed-to-will-paginate/138000/1 "2008-05-19T11:49:37Z")

</div>

Hi  
Till now we used the rails pagination.But now onwards shifting to  
will\_paginate  
The code I use currently is as below .This is with the help of  
find\_where pluggin…A fantastic pluggin which we still want to use…I  
would like to know how can i modify the following code to work with  
will\_paginate

step 1: set the variables you’ll need  
page = (params[:page] ||= 1).to\_i  
items\_per\_page = 20  
offset = (page - 1) \* items\_per\_page  
# step 2: instead of performing the full find, just find the  
record count

```
        @search_sd_ticket_count_result =

```

ServiceDeskTicket.find\_where(:all,:select=\>‘count(\*) as count1’ ) do  
|sd|  
sd.number.downcase =~  
“%”+@sd\_ticket\_number.downcase+"%" if !@sd\_ticket\_number.nil?  
sd.service\_desk\_status\_id==  
@sd\_ticket\_status\_id  
sd.service\_desk\_priority\_id==  
@sd\_ticket\_priority\_id  
sd.primary\_assignee==  
@sd\_ticket\_primary\_assignee  
sd.created\_on \<=\>  
(@sd\_ticket\_start\_date…@sd\_ticket\_end\_date) if  
!@sd\_ticket\_start\_date==nil and !@sd\_ticket\_end\_date==nil  
end

```
        record_count=@search_sd_ticket_count_result[0].count1.to_i

        # step 3: create a Paginator, the second variable has to be

```

the number of ALL items on all pages  
@search\_sd\_ticket\_result\_pages = Paginator.new(self,  
record\_count, items\_per\_page, page)

```
        # step 4: only find the requested subset of

```

@search\_sd\_ticket\_result

# @search\_sd\_ticket\_result =

ServiceDeskTicket.find\_where(:all,:offset=\>offset,:limit=\>items\_per\_page  
) do |sd|  
sd.number.downcase =~  
“%”+@sd\_ticket\_number.downcase+"%" if !@sd\_ticket\_number.nil?  
sd.service\_desk\_status\_id==  
@sd\_ticket\_status\_id  
sd.service\_desk\_priority\_id==  
@sd\_ticket\_priority\_id  
sd.primary\_assignee==  
@sd\_ticket\_primary\_assignee  
sd.created\_on \<=\>  
(@sd\_ticket\_start\_date…@sd\_ticket\_end\_date) if  
!@sd\_ticket\_start\_date==nil and !@sd\_ticket\_end\_date==nil

```
                             end

```

I could do will\_paginate with imple cases like  
@sd\_attachments=@sd\_ticket.sd\_attchments.paginate  
:per\_page=\>20,:page=\>params[:page] and in view \<%= will\_paginate %\>  
.But how can I convert the above to use will\_paginate  
Thanks in advance  
Sijo
