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