Moving pagination code to model

Hi
I have the controller code as below

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|

                             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|

                             end

How can I move this code to model so that to call it other places also

Sijo