Created
February 26, 2015 06:22
-
-
Save michaellouieloria/c8536cb3171c0396152f to your computer and use it in GitHub Desktop.
Sort merged activerecord objects in Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@posts = @posts1 + @posts2 | |
#Descending | |
@posts.sort! {|x,y| y.created_at <=> x.created_at} | |
#Ascending | |
@posts.sort! {|x,y| x.created_at <=> y.created_at} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment