Hello, I am using acts_as_commentable (related to Post) and I would like to know how to get the list the posts ordered by date of comment (i.e. post with recent comment first). in addition if a post has no comment, i would it to be inserted based on its creation date. Thanks for your help Nicolas --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Here''s how I did it last night after about an hour of googling the shit out of it and coming up empty. # First I load all the messages @messages = Message.all # Then I loop through them all, and if a message has a comment, # I change the message''s created_at field to the comments created_at @messages.each do |message| comment = message.comments.find(:first, :order => ''created_at DESC'') message.created_at = comment.created_at unless comment.blank? end # Then I sort the messages by their (new) created_at dates, which don''t # get saved so they don''t overwrite their real created_at fields. @messages.sort! { |b,a| a.created_at <=> b.created_at } # Then I take the top 5 to use in my dashboard view. @messages = @messages[0..4] This works regardless of whether a Message (or Post in your case) has any comments. This looks a little hackish to me, so please, Rails gurus, have at it. Hope this helps! Morgan Currie On Aug 30, 6:46 am, Tranquiliste <nico...-y4fycU/S73DV4ymnR38j3w@public.gmane.org> wrote:> Hello, > > I am usingacts_as_commentable(related to Post) and I would like to > know how to get the list the posts ordered by date of comment (i.e. > post with recent comment first). > > in addition if a post has no comment, i would it to be inserted based > on its creation date. > > Thanks for your help > > Nicolas--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jose vicente Ribera pellicer
2008-Nov-22 16:14 UTC
Re: acts_as_commentable: find Post by date of comment
Hi, it works fine witn ruby 2.x?? I''m very interested. I read the it doesn´t work with this version, see this comments: http://agilewebdevelopment.com/plugins/acts_as_commentable and I´m using rails 2.0.2 -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The Ruby on Rails web application framework has built up a tremendous head of steam over the last year. Fueled by some significant benefits and an impressive portfolio of real-world applications already in production, Rails is destined to continue making significant inroads in 2006. Simply put, Ruby on Rails is an open source tool that gives you the advantage of rapidly creating great web applications backed by SQL databases to keep up with the speed of the web. ------------------------ kesha <a href="http://www.casualdate.net.au">Friends Dating</a> -- 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 -~----------~----~----~----~------~----~------~--~---
Message.all.sort_by { |m| m.comments.blank? ? m.created_at : m.comments.last.created_at }[0..4] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---