has_breadcrumbs
has_breadcrumbs is a simple plugin that adds a breadcrumb object into controllers and views.
Installation
Rails 2.3:
config.gem 'has_breadcrumbs'
Bundler:
gem 'has_breadcumbs'
Usage
On your controller:
class ApplicationController < ActionController::Base
before_filter :add_home_breadcrumb
protected
def
.add 'Home', root_path
end
end
class PostsController < ApplicationController
def index
.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:
.add 'Some page'
You can set additional HTML attributes if you need to:
.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 Gabriel Sobrinho, under the MIT license.