Hi all, Iam having some doubts regarding sorting in rails based on date. I have two models. Post and message. Post has_many messages. Message belongs_to post. Message has a field called publish_on. So i want to sort all posts based on publish_on date in the following order. Let us assume that the current date is 10th November and there are 6 posts with publish dates as 8,9,10,11,12 and 13 respectively so the sortng of the posts will be as follows, Post to be published on 10th November Post to be published on 11th November Post to be published on 12th November Post to be published on 13th November Post to be published on 9th November Post to be published on 8th November Thanks, P.Angel -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 November 2011 11:32, angel david <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi all, > > Iam having some doubts regarding sorting in rails based on date. > > I have two models. Post and message. > Post has_many messages. > Message belongs_to post. > > Message has a field called publish_on. > > So i want to sort all posts based on publish_on date in the following > order. > > Let us assume that the current date is 10th November and there are 6 > posts with publish dates as 8,9,10,11,12 and 13 respectively so the > sortng of the posts will be as follows, > > > Post to be published on 10th November > > Post to be published on 11th November > > Post to be published on 12th November > > Post to be published on 13th November > > Post to be published on 9th November > > Post to be published on 8th NovemberYou could do that using two separate find operations and then concatenating them, or you could use sort with a block and put the logic in the block. I expect someone will point out a better way. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #1033691:> On 25 November 2011 11:32, angel david <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> So i want to sort all posts based on publish_on date in the following >> >> Post to be published on 12th November >> >> Post to be published on 13th November >> >> Post to be published on 9th November >> >> Post to be published on 8th November > > You could do that using two separate find operations and then > concatenating them, or you could use sort with a block and put the > logic in the block. I expect someone will point out a better way. > > ColinHi Colin, Thanks for your reply. I did it as you said.. Got two different find operations and concatenated them.. Once again thanks for your support Angel -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.