Breadcrumbs in Ruby on Rails

breadcrumbs, controller, ruby, ruby-on-rails

Solution

This is mostly a matter of opinion, but anyway:

- I would not want that much logic in a view. We've probably all done it, but it gets messy quickly.

- The code is not safe against future changes that affect the depth of the tree.

- Instead of linked variables `*_name` and `*_link`, I'd suggest using proper objects anyway, with some `link_to` functionality.

You might find Episode 162 of Railscasts of interest for a nice solution that gets by with

<% for page in @page.ancestors.reverse %>
  <%= link_to h(page.name), page %> &gt;
<% end %>

Problem

I'm slightly insecure about my breadcrumb solution. Names and links are defined in each controller action: ``` <a href="http://localhost:3000/">Home</a> <% if defined? @l1_link %> > <a href="<%= @l1_link%>"><%= @l1_name %></a> <% if defined? @l2_link %> > <a href="<%= @l2_link%>"><%= @l2_name %></a> <% end %> <% end %> ``` This way I can use: ``` @l1_link = user_path() ``` Question: As I am not that smart - could this kind of system lead to desaster somewhere down the road? Is this (grossly) inefficient?

Original source

Related problems