has_breadcrumbs

has_breadcrumbs is a simple plugin that adds a breadcrumb object into controllers and views.

Instalation

You can install using as gem:


Rails::Initializer.run do |config|
  config.gem 'has_breadcrumbs'
end

or install as plugin with `script/plugin install git://github.com/sobrinho/has_breadcrumbs.git`

Usage

On your controller:


class ApplicationController < ActionController::Base
  before_filter :add_initial_breadcrumb

  protected

  def add_initial_breadcrumb
    breadcrumb.add 'Home', root_path
  end
end

class PostsController < ApplicationController
  def index
    # you can also use << instead of add
    breadcrumb.add 'Posts', posts_path
  end
end

You don’t need to provide an URL; in that case, a span will be generated instead of a link:


breadcrumb.add 'Some page'

You can set additional HTML attributes if you need to:


breadcrumb.add 'Home', root_path, :id => 'home', :title => 'Go to the home page'

On your view:

You are here: <%= breadcrumb.display %>

The output in your html will be something like below:


  <ul id="breadcrumbs">
    <li class="item-0"><a href="#">Home</a></li>
    <li class="item-1"><a href="#">Main section</a></li>
    <li class="item-2"><a href="#">Sub section</a></li>
    <li class="item-3 last">The page you are on right now</li>
  </ul>

For a good css example take a look in examples folder.

This work is based on http://github.com/fnando/has_breadcrumbs by Nando Vieira.

Adaptation made by Daniel Lopes and gemified by Gabriel Sobrinho, under the MIT license.