From: Dominik Krebs Date: 2009-01-05T23:35:09+09:00 Subject: Hash is not merged / recursive function Hi, i'm new to ruby, but i really like it. I'm trying to extend Ruby on Rails FormHelper with a custom function which returns a recursive tree select field for "acts_as_tree"-models. My Problem is, that the hash is not being merged correctly and so i only get values which are up to the root of the tree. Thanks for all answers. Here's my code: module ActionView module Helpers class FormBuilder def tree_select_options(collection, value_method, text_method, level = 0) choices = {} collection.map do |element| choices[" " * level + element.send(text_method)] = element.send(value_method) if (element.children.size > 0) choices.merge(tree_select_options(element.children, value_method, text_method, level+5)) end end return choices end def tree_select(method, collection, value_method, text_method, options = {}, html_options = {}) choices = tree_select_options(collection, value_method, text_method) @template.select(@object_name, method, choices, options.merge(:object => @object), html_options) end end end end -- Posted via http://www.ruby-forum.com/.