# Strategy for partials needed--DRYing up list-generating code

**URL:** <https://www.ruby-forum.com/t/strategy-for-partials-needed-drying-up-list-generating-code/143360>\
**Category:** Rails\
**Created:** [July 17, 2008, 5:19pm UTC](https://www.ruby-forum.com/t/strategy-for-partials-needed-drying-up-list-generating-code/143360 "2008-07-17T17:19:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [July 17, 2008, 5:19pm UTC](https://www.ruby-forum.com/t/strategy-for-partials-needed-drying-up-list-generating-code/143360/1 "2008-07-17T17:19:34Z")

</div>

Hey All,

I’m fighting the urge to just copy/paste view template code & would like  
advice on a better strategy.

Consider this model:

Project  
name  
start\_date  
status \*  
funder \*  
funding\_mechanism \*  
\<etc.\>

Where the \*'d attributes are references to other models. I want to  
generate tables listing projects in all of these views:

1. projects/index
2. statuses/4/show
3. funders/2/show
4. funding\_mechanisms/4/show

For #1, I want to show all of the columns of the projects, but for the  
others, I want to leave out whichever column is redundant given the  
thing I’m "show"ing. So for instance, say /statuses/4 is the ‘active’  
status. I want to caption my table “Projects that are currently  
Active”, and then show all of the project columns except for status.  
Likewise, for funders/2 I want a caption “Projects funded by NCI”, and  
to show all columns except for funder.

Optimally, this would all be in a single partial that would morph  
depending on the context from which I called it. Is there a way to  
write that partial w/out making it a hell-broth of if/then statements?  
Or is that just a butt-kicking I’ve got to take?

Thanks!

-Roy

Roy P.  
Research Analyst/Programmer  
Group Health Center For Health Studies (Cancer Research Network)  
(206) 287-2078  
Google Talk: rpardee
