Created
July 25, 2009 20:43
-
-
Save rubiety/154971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def tree_options_from_collection_for_select(objects, value = :id, name = :name, selected = nil, options = {}) | |
options[:indent_with] ||= '- ' | |
options[:level] ||= 0 | |
objects.inject([]) do |entries, object| | |
entries << [options[:indent_with] * options[:level] + object.send(name), object.send(value)] | |
entries += tree_options_from_collection_for_select(object.children, value, name, selected, options.merge(:level => options[:level] + 1)) | |
entries | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment