# To avoid repeated pagination code

**URL:** <https://www.ruby-forum.com/t/to-avoid-repeated-pagination-code/132834>\
**Category:** Rails\
**Created:** [March 25, 2008, 5:43am UTC](https://www.ruby-forum.com/t/to-avoid-repeated-pagination-code/132834 "2008-03-25T05:43:30Z")\
**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:** [March 25, 2008, 5:43am UTC](https://www.ruby-forum.com/t/to-avoid-repeated-pagination-code/132834/1 "2008-03-25T05:43:30Z")

</div>

Hi  
Below is the code for controller service\_desk show action(some  
portion only)  
def show  
@sd\_attachments=service\_desk\_ticket.service\_desk\_attachments.paginate  
:page =\> params[:page], :per\_page =\> 15  
@sd\_activities=ServiceDeskActivity.find\_all\_by\_service\_desk\_ticket\_id(service\_desk\_ticket.id)paginate  
:page =\> params[:page], :per\_page =\> 15

end

```
HERE THE show.rhtml contains differnt tabs like

```

Attachments,Activities etc…  
And I use Ajax for pagination in all these tabs…Suppose for example  
sd\_attachments first show say 15 attachments, then to get next 15, I  
again have to write the same pagination code as in show for this  
sd\_attachments in the controller…(In another file)And by using RJS  
replacing the div (The sd\_attachment is complete inside a div)…BUT THE  
PROBLEM IS EVEN IF THE CODE FOR PAGINATION IS THERE IN show ACTION I  
HAVE TO WRITE IT AGAIN AND AGAIN FOR EACH TAB…HOW CAN I AVOID THIS.?

Sijo
