I want the hashes in @new_array to be sorted by @new_array_ids. At first
I thought I would just be able to use :order => @new_array_ids, or
something like that in the find. But the :order option only takes SQL
fragments (?). So in order to get something like:
I need to identify the position of each element in @new_array_ids, find
each of the attributes whose id matches a value in @new_array_ids, sort
by the order of values in @new_array_ids.
I new to ruby + rails, so please let me know if there’s a really simple
way of doing this. Thanks.
(which I’d have put on a single line if it weren’t for the inevitable
line-wrapping in the email)
In fact, if you didn’t want to sort the results, you could have
skipped the mapping .to_i since ActiveRecord will treat .find(“3”)
and .find(3) the same.
You can even simplify that bit using Symbol#to_proc