Skip to content

Instantly share code, notes, and snippets.

@dangalipo
Created March 9, 2011 09:13
Show Gist options
  • Save dangalipo/861919 to your computer and use it in GitHub Desktop.
Save dangalipo/861919 to your computer and use it in GitHub Desktop.
def generate_breadcrumbs(current, breadcrumbs)
if current.root?
[current.id]
elsif breadcrumbs.present?
traverse_breadcrumbs(current, breadcrumbs)
end
end
def traverse_breadcrumbs(current, breadcrumbs)
parent_ids = current.parents.collect{|c| c.id }
if parent_ids.include?(breadcrumbs.last)
breadcrumbs << current.id
else
rewind_breadcrumbs(current, breadcrumbs)
end
end
def rewind_breadcrumbs(current, breadcrumbs)
if breadcrumbs.include?(current.id)
while breadcrumbs.last != current.id do
breadcrumbs.pop
end
breadcrumbs
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment