Rails/ActiveRecord order by Array
ActiveRecord中如果想根据自定义的一个数组id集合排序:
ids = [2,1,3] users = User.where("id in (?)",ids) results = ids.map{|id| users.detect{|each| each.id == id}}
ActiveRecord中如果想根据自定义的一个数组id集合排序:
ids = [2,1,3] users = User.where("id in (?)",ids) results = ids.map{|id| users.detect{|each| each.id == id}}