Gretel is a Ruby on Rails plugin that makes it easy yet flexible to create breadcrumbs.
In your Gemfile:
gem 'gretel'
And run bundle install
.
Start by generating initializer:
$ rails generate gretel breadcrumbs
In config/initializers/breadcrumbs.rb
:
Gretel::Crumbs.layout do crumb :root do link "Home", root_path end crumb :projects do link "Projects", projects_path, { :class => 'breadcrumb', :style => 'font-weight: bold;' } end crumb :project do |project| link lambda { |project| "#{project.name} (#{project.id.to_s})" }, project_path(project) parent :projects end crumb :project_issues do |project| link "Issues", project_issues_path(project) parent :project, project end crumb :issue do |issue| link issue.name, issue_path(issue) parent :project_issues, issue.project end end
In app/views/layouts/application.html.erb
:
<%= breadcrumb :pretext => "You are here:", :separator => ">", :autoroot => true, :show_root_alone => true, :link_last => false %>
In app/views/xx/xx.html.erb
:
<% breadcrumb :issue, @issue %>
This could also be done in the controller, if you prefer:
def show @project = Project.find(params[:id]) breadcrumb :project, @project end
Options for <%= breadcrumb %>
:
:pretext Text to be rendered before breadcrumb, if any. Default: none :separator Separator between links. Default: > :autoroot Whether it should automatically link to :root if no root parent is given. Default: false :show_root_alone Whether it should show :root if this is the only link. Default: false :link_last Whether the last crumb should be linked to. Default: false
Copyright © 2010 Lasse Bunk, released under the MIT license