zen_breadcrumbs

zen_breadcrumbs is a Ruby on Rails plugin for creating a breadcrumbs navigation. This is characterized by simplicity. You just have to write one method in one line to render a breadcrumbs navigation.

Instration

Put this line in your Gemfile:

gem 'zen_breadcrumbs'

Then run the bundle command to install it.

Usage

In your view, call breadcrumbs helper method to render a breadcrumbs navigation.
breadcrumbs requires two parameters: the array of breadcrumbs names and the array of the target paths.

<%= breadcrumbs %w(Home Mypage Favorite), [root_path, mypage_path] %>

breadcrumbs generates html sentence as below.

<ol class="breadcrumbs-box">
  <li class="breadcrumbs-list">
    <a class="breadcrumbs-link" href="/">Home</a>
  </li>
  <span class="breadcrumbs-separator">&gt;</span>
  <li class="breadcrumbs-list">
    <a class="breadcrumbs-link" href="/">Mypage</a>
  </li>
  <span class="breadcrumbs-separator">&gt;</span>
  <li class="breadcrumbs-list">Favorite</li>
</ol>

The third parameter is a hash of options to customize the breadcrumbs navigation.

Possible options are:

  • :separator - default value is '>'
  • :css_prefix - default value is 'breadcrumbs'

The example of using options is here.

<%= breadcrumbs %w(Home Mypage), [root_path], separator: '|', css_prefix: 'mobile-crumbs' %>

HTML:

<ol class="mobile-crumbs-box">
  <li class="mobile-crumbs-list">
    <a class="mobile-crumbs-link" href="/">Home</a>
  </li>
  <span class="mobile-crumbs-separator">|</span>
  <li class="mobile-crumbs-list">Mypage</li>
</ol>