liftedmedia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-08 16:22 UTC
partial repeating the output from a collection
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?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> @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... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---