Limiting records in a model action...
- by bgadoci
How do I limit the number of records that I am outputting with the following code to only 3 records:
User.rb
def workouts_on_which_i_commented
comments.map{|x|x.workout}.uniq
end
def comment_stream
workouts_on_which_i_commented.map do |w|
w.comments
end.flatten.sort{|x,y| y.created_at <=> x.created_at}
end
html.erb file
<% current_user.comment_stream.each do |comment| %>
...
<% end %>
UPDATE:
I'm using Rails 2.3.9