# DRYing some controller code

**URL:** <https://www.ruby-forum.com/t/drying-some-controller-code/140366>\
**Category:** Rails\
**Created:** [June 13, 2008, 10:22am UTC](https://www.ruby-forum.com/t/drying-some-controller-code/140366 "2008-06-13T10:22:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [June 13, 2008, 10:22am UTC](https://www.ruby-forum.com/t/drying-some-controller-code/140366/1 "2008-06-13T10:22:56Z")

</div>

def index  
if not @contest.nil?  
@videos = Video.paginate( :all, :include =\> { :ad  
=\> :contest }, :page =\> params[:page],  
:conditions =\> [ “videos.state = ‘published’ AND  
contests.slug = ?”, @contest.slug ] )  
else  
@videos = Video.paginate( :all, :conditions =\> { :state =\>  
‘published’ }, :page =\> params[:page] )  
end  
end

def parade  
if not @contest.nil?  
@videos = Video.paginate( :all, :include =\> { :ad  
=\> :contest }, :page =\> params[:page],  
:conditions =\> [ “videos.state = ‘published’ AND  
contests.slug = ?”, @contest.slug ],  
:order =\> “ads.score DESC” )  
else  
@videos =\> Video.paginate( :all, :conditions =\> { :state =\>  
‘published’ },  
:order =\> “ads.score DESC”, :page =\> params[:page] )  
end  
end

@contest gets populated in a before\_filter.  
there’s definitely too much repetition in here, how do you suggest  
cleaning up the whole thing ? I was thinking at building different  
conditions arrays inside the filter but I’m not so sure about it.  
Suggestions ?

TIA,  
ngw
