Skip to content

Instantly share code, notes, and snippets.

@teamon
Created August 8, 2008 16:08
Show Gist options
  • Save teamon/4578 to your computer and use it in GitHub Desktop.
Save teamon/4578 to your computer and use it in GitHub Desktop.
def full_path_data_with_children
(self.ancestors << self).map { |e|
pid = e.id == 1 ? 0 : e.id
{ :id => pid, :data => e.children.sort.map { |i| { :id => i.id, :name => i.name, :parent_id => pid } } }
}.flatten
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment