# Partial repeating the output from a collection

**URL:** <https://www.ruby-forum.com/t/partial-repeating-the-output-from-a-collection/111573>\
**Category:** Rails\
**Created:** [August 8, 2007, 6:39pm UTC](https://www.ruby-forum.com/t/partial-repeating-the-output-from-a-collection/111573 "2007-08-08T18:39:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 8, 2007, 6:39pm UTC](https://www.ruby-forum.com/t/partial-repeating-the-output-from-a-collection/111573/1 "2007-08-08T18:39:11Z")

</div>

I have an array I’m trying to output with partials. The query find  
entries in the database correctly but the results are getting  
outputted repeatedly.

## For example, if there are 3 results from the query it would display the 3 partials 3 times, if it was 4 it would repeat 4 times etc. Heres what it would look like if "@albums = Album.find(@albumids) " found 3 ID’s

## First Partial (id=1) Second Partial (id=2) Third Partial (id=3) First Partial (id=1) Second Partial (id=2) Third Partial (id=3) First Partial (id=1) Second Partial (id=2) Third Partial (id=3)

Heres the array and query

```
 @activity = Activity.count( :group => 'album_id',
                             :conditions => ['created_at >= ?',

```

@time],  
:order =\> “count\_all DESC”,  
:limit =\> 5 )  
@albumids = @activity.map { |a| a[0] }  
@albums = Album.find(@albumids)

And partial line

\<%= render :partial =\> “album”, :collection =\> @albums %\>

Any thoughts?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 9, 2007, 9:16am UTC](https://www.ruby-forum.com/t/partial-repeating-the-output-from-a-collection/111573/2 "2007-08-09T09:16:32Z")

</div>

> ```
> @albums = Album.find(@albumids)
> 
> ```
> 
> And partial line
> 
> \<%= render :partial =\> “album”, :collection =\> @albums %\>
> 
> Any thoughts?

I suspect you have a problem with the query that sets up @albumids; your  
render line will generate a line for each object in the @albums  
collection, so if you are seeing the same album repeated, it is likely  
because it is repeated in the @albums collection.

You could check this by running ruby script/console, and testing your  
find logic by entering the three lines:  
@activity = Activity.count( :group =\> ‘album\_id’,  
:conditions =\> [‘created\_at \>= ?’,  
@time],  
:order =\> “count\_all DESC”,  
:limit =\> 5 )  
@albumids = @activity.map { |a| a[0] }  
@albums = Album.find(@albumids)

Hope this helps…
