I'm building a sorted hash for use in a grouped select in a rails app. I am not using ActiveRecord. Is there a more efficient or cleaner way than this?
def for_select
select_list = {}
Department.all.each do |dept|
select_list[dept.top_level_department_cn] ||= []
select_list[dept.top_level_department_cn] << [dept.cn, dept.sorid]
end
select_list.each_value { |select_options| select_options.sort_by!(&:first) }
.sort
.to_h
end