Limiting records in a model action...

Posted by bgadoci on Stack Overflow See other posts from Stack Overflow or by bgadoci
Published on 2010-12-28T21:30:55Z Indexed on 2010/12/28 21:53 UTC
Read the original article Hit count: 140

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby