# Help with partials / pagination strategy

**URL:** <https://www.ruby-forum.com/t/help-with-partials-pagination-strategy/112428>\
**Category:** Rails\
**Created:** [August 18, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/help-with-partials-pagination-strategy/112428 "2007-08-18T20:35:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [August 18, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/help-with-partials-pagination-strategy/112428/1 "2007-08-18T20:35:49Z")

</div>

Hi,

I have a few simple lists that I’m displaying all over my site, as  
paginated partials.

Sometimes a given list shows 5 items, sometimes 10, sometimes 20,  
depending on what page is being displayed. Sometimes a list is sorted  
by one criterion, sometimes by another.

So, being a newbie, I’ve ended up with many different actions to  
display and to paginate each partial. Lots and lots of actions.

What I’d really like is one pagination action, and one display action,  
per partial, or maybe just one action per partial for both. How is  
this done?  
It’s very cool how I can instantiate an object, in list context,  
inside an action, then pick up that object in a partial to display  
and / or paginate the partial, with just a few lines of code, but it  
might be far easier to just have one or two actions, with a bunch of  
settings for list size and sorting, to display each partial.

Any ideas?

Charlie

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [August 20, 2007, 6:18am UTC](https://www.ruby-forum.com/t/help-with-partials-pagination-strategy/112428/2 "2007-08-20T06:18:53Z")

</div>

If it were me, I would write function in application.rb that would do  
the dirty work, then have each controller call that function to populate  
the needed instance variable. eg:

class ApplicationController \< ActionController::Base

def WidgetPagnation(amount,offset,order)  
Widget.find(:all, :limit=\>number, :offset=\>offset, :order=\>order)  
end

end

You may need to add additional constraints that find, and will need to  
deal with the edge cases where the search is empty, or returns less then  
the requested number of results. I would do that in display logic for  
the partial, but web design purists might want it in the controller  
instead.

JFMiller

charlie caroff wrote:

> Hi,
> 
> I have a few simple lists that I’m displaying all over my site, as  
> paginated partials.
> 
> Sometimes a given list shows 5 items, sometimes 10, sometimes 20,  
> depending on what page is being displayed. Sometimes a list is sorted  
> by one criterion, sometimes by another.
> 
> So, being a newbie, I’ve ended up with many different actions to  
> display and to paginate each partial. Lots and lots of actions.
> 
> What I’d really like is one pagination action, and one display action,  
> per partial, or maybe just one action per partial for both. How is  
> this done?  
> It’s very cool how I can instantiate an object, in list context,  
> inside an action, then pick up that object in a partial to display  
> and / or paginate the partial, with just a few lines of code, but it  
> might be far easier to just have one or two actions, with a bunch of  
> settings for list size and sorting, to display each partial.
> 
> Any ideas?
> 
> Charlie

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [August 21, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/help-with-partials-pagination-strategy/112428/3 "2007-08-21T18:33:14Z")

</div>

JF, Thanks very much for your post –

Charlie

On Aug 19, 9:18 pm, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
