diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index 32225d83..48527a9b 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -18,14 +18,17 @@ module WikiHelper def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0) + pages = pages.group_by(&:parent) unless pages.is_a?(Hash) s = '' - pages.select {|p| p.parent == parent}.each do |page| - attrs = "value='#{page.id}'" - attrs << " selected='selected'" if selected == page - indent = (level > 0) ? (' ' * level * 2 + '» ') : nil - - s << "\n" + - wiki_page_options_for_select(pages, selected, page, level + 1) + if pages.has_key?(parent) + pages[parent].each do |page| + attrs = "value='#{page.id}'" + attrs << " selected='selected'" if selected == page + indent = (level > 0) ? (' ' * level * 2 + '» ') : nil + + s << "\n" + + wiki_page_options_for_select(pages, selected, page, level + 1) + end end s end