Skip to content

Instantly share code, notes, and snippets.

@avescodes
Created June 16, 2009 18:23
Show Gist options
  • Save avescodes/130809 to your computer and use it in GitHub Desktop.
Save avescodes/130809 to your computer and use it in GitHub Desktop.
def self.parent_select_options
options = [['-- No Parent --', nil]]
Tag.recurse_for_parent_select_options(Tag.roots,options)
return options
end
def self.recurse_for_parent_select_options(nodes,options)
nodes.each do |node|
prefix = node.depth > 0 ? ' -' * node.depth + ' ' : ''
options << [ prefix + node.title, node.id]
Tag.recurse_for_parent_select_options(node.children,options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment