# to avoid repeated pagination code

**URL:** <https://discuss.rubyonrails.org/t/to-avoid-repeated-pagination-code/26805>\
**Category:** rubyonrails-talk\
**Created:** [March 25, 2008, 4:43am UTC](https://discuss.rubyonrails.org/t/to-avoid-repeated-pagination-code/26805 "2008-03-25T04:43:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 25, 2008, 4:43am UTC](https://discuss.rubyonrails.org/t/to-avoid-repeated-pagination-code/26805/1 "2008-03-25T04:43:30Z")

</div>

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

&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;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
