0.0
No commit activity in last 3 years
No release in over 3 years
Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Crummy

Introduction

Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.

Install

The gem is hosted on gemcutter, so if you haven’t already, add it as a gem source:

  
    gem sources -a http://gemcutter.org/
  

Then install the Crummy gem:

  
    gem install crummy
  

You can also install it as a Rails plugin:

  
    script/plugin install git://github.com/zachinglis/crummy.git
  

Example

In your controllers you may add_crumb either like a before_filter or within a method (It is also available to views).

  
    class ApplicationController
      add_crumb "Home", '/'
    end
    
    class BusinessController < ApplicationController
      add_crumb("Businesses") { |instance| instance.send :businesses_path }
      add_crumb("Comments", :only => "comments") { |instance| instance.send :businesses_comments_path }
      before_filter :load_comment, :only => "show"
      add_crumb :comment, :only => "show"
  
      def show
        add_crumb @business.display_name, @business
      end
      
      def load_comment
        @comment = Comment.find(params[:id])
      end
    end
  

Then in your view:

  
    <%= render_crumbs %>
  

Options for render_crumb_

render_crumbs renders the list of crumbs as either html or xml

It takes 3 options

The output format. Can either be :xml or :html. Defaults to :html

:format => (:html|:xml|:html_with_list)

The seperator text. It does not assume you want spaces on either side so you must specify. Defaults to &raquo; for :html and <crumb> for :xml

:seperator => string

Render links in the output. Defaults to true

:link => boolean

Examples

 
  render_crumbs                     #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
  render_crumbs :seperator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
  render_crumbs :format => :xml     #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
  render_crumbs :seperator => ' > ', :format => :html_with_list 
  #=> <ul class="breadcrumb"><li><a href="/">Home</a></li><li><a href="/businesses">Businesses</a></li></ul>
 

A crumb with a nil link will just output plain text.

Notes

The variable set is set to @_crumbs as to not conflict with your code.

Todo

  • Port over rspecs from project to plugin (Fully tested in a project)
  • Accept instances of models as a single argument
  • Allow for variables in names. (The workaround is to do your own before_filter for that currently)

Credits

Copyright © 2008 Zach Inglis, released under the MIT license