Skip to content

Instantly share code, notes, and snippets.

@rsl
Created September 11, 2013 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsl/6529686 to your computer and use it in GitHub Desktop.
Save rsl/6529686 to your computer and use it in GitHub Desktop.
this seems to do what i want
def self.find_by_ordered_ids(ids)
order_by = ['case']
ids.each_with_index do |id, index|
order_by << "WHEN id='#{id}' THEN #{index}"
end
order_by << 'end'
where(id: ids).order(order_by.join(' '))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment