Created
September 13, 2010 18:42
-
-
Save yellow5/577787 to your computer and use it in GitHub Desktop.
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
ordered_ids = [5,2,3,1,4] # some array of ordered ids | |
records = Record.find(ordered_ids) # find the records that go with the ordered_ids | |
# loop the records and store them in a temp hash | |
temp_hash = {} | |
records.each do |record| | |
temp_hash[record.id] = record | |
end | |
# convert the temp_hash into a new array | |
ordered_records = ordered_ids.map{|i| temp_hash[i]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment