Created
March 9, 2011 09:13
-
-
Save dangalipo/861919 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
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