Add a method on your model to search for the parent
class Category
# inline, less memory usage
def last_parent
last = self
while last.parent
last = last.parent
end
last
end
# recursive, better readability
def last_parent_recursive
if parent
parent.last_parent_recursive
else
self
end
end
end
then, on your view:
<%= @cat.last_parent %>