I''m trying to wrap my head around this idea, and thought I might be able to solicit the help of the community a little bit. @comments = Finding all comments for a particular thread. - Each comment has a date of when it was posted. - I would like to display all comments that were posted in the past 7 days in one area, and then display all older comments in another. - I could imagine doing this as two separate database queries, but is there a way to modify a for loop to run through them for me? - How do you handle the date selection to use the current day - 7? -- 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 -~----------~----~----~----~------~----~------~--~---
Elliot, Sounds like a good candidate for :named_scope (http:// api.rubyonrails.com/classes/ActiveRecord/NamedScope/ ClassMethods.html#M001246) named_scope :recent, :conditions => [''created_at > ?'', 7.days.ago.to_s(:db)] named_scope :older, :conditions => [''created_at <= ?'', 7.days.ago.to_s(:db)] @recent_comments = thread.comments.recent @older_comments = thread.comments.older As to cutting down to one db call, generally, it won''t hurt to have two db calls but maybe someone else has a way. On Aug 27, 12:11 pm, Elliot Chyba <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m trying to wrap my head around this idea, and thought I might be able > to solicit the help of the community a little bit. > > @comments = Finding all comments for a particular thread. > > - Each comment has a date of when it was posted. > > - I would like to display all comments that were posted in the past 7 > days in one area, and then display all older comments in another. > > - I could imagine doing this as two separate database queries, but is > there a way to modify a for loop to run through them for me? > > - How do you handle the date selection to use the current day - 7? > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
On 27 Aug 2008, at 19:11, Elliot Chyba <rails-mailing-list@andreas- s.net> wrote:> > I''m trying to wrap my head around this idea, and thought I might be > able > to solicit the help of the community a little bit. > > @comments = Finding all comments for a particular thread. > > - Each comment has a date of when it was posted. > > - I would like to display all comments that were posted in the past 7 > days in one area, and then display all older comments in another. > > - I could imagine doing this as two separate database queries, but is > there a way to modify a for loop to run through them for me? >If you''re happy doing it in ruby, the partition function is probably what you''re after Fred> - How do you handle the date selection to use the current day - 7? > -- > 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 -~----------~----~----~----~------~----~------~--~---