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?
You could also use Ariane http://github.com/simonc/ariane
With it you can generate any kind of breadcrumb, as links in a paragraph or as a ul/li :)
If you want something specific, you can create your own renderer.
It's pretty simple to use, just add this in a
before_filter
:Do not use any plugins just for breadcrumbs. This link provides an efficient method to generate breadcrumbs.
http://szeryf.wordpress.com/2008/06/13/easy-and-flexible-breadcrumbs-for-rails/
Although, it is a very old post, it still works.
This is mostly a matter of opinion, but anyway:
*_name
and*_link
, I'd suggest using proper objects anyway, with somelink_to
functionality.You might find Episode 162 of Railscasts of interest for a nice solution that gets by with
Breadcrumbs menu are a recurrent pattern in most Rails applications. To solve this issue, I created and released a plugin called breadcrumbs_on_rails.
You define your breadcrumbs in the controller
and you render them in your view.
Even if you don't want to use a plugin, I encourage you to give it a look. It's open source and you can grab some idea for your app.
I did a fork of
crumble
gem. It has very few configuration options and it appears abandoned, but when I tried to switch tobreadcrumbs_on_rails
orgretel
, I realized that I have to add many lines to my views or controllers (and I have a lot of them), but withcrumble
it is all stored in one configuration file. If you like to do some patches and prefer configuration in one place, I think it is the best solution ever.Here are two approaches:
Split the URL and display it
A more flexible solution implemented in the controller where you setup the breadcrumbs in the controller: Easy and Flexible Breadcrumbs for Rails