Introducing Crummy

I have worked on many applications that require breadcrumbs. Every time, one of the developers has built a quick custom solution. Finally, I decided that we needed a complete solution that we could easily add to future projects, and thus Crummy was born.

Requirements

I set a few requirements that must be fulfilled in order for me to call the plugin a success. They were:

  • Ability to add breadcrumbs at Controller class level (like a before filter)
  • Ability to add breadcrumbs in the controller methods (such as actions)
  • Ability to add breadcrumbs from the views
  • Ability to add breadcrumbs with or without an url
  • No variable conflicts (such as instance variables)
  • Full and strong spec coverage
  • Good documentation

I managed to fulfill these requirements and add a few shiny methods to make life easy.

Examples of Usage

    class ApplicationController < ActionController::Baseee
      add_crumb 'Home', '/' # This will display on EVERY list of breadcrumbs
    end
  


    class BusinessController < ApplicationController
      # The load order DOES matter.
      add_crumb("Businesses") { |instance| instance.send :businesses_path } # Show on all actions
      add_crumb("Comments", :only => [:comments, :show]) { |instance| instance.send :business_comments_path } # Only add the comments link on the comments and show actions.
      before_filter :load_comment, :only => "show"

      def show
       add_crumb @business.display_name, @business
      end

      def load_comment
       @comment = Comment.find(params[:id])
      end
    end
  

Golden Feature

One of the most useful argument usage is add_crumb :comment. What this does is turns the symbol into an instance variable (@comment.) Then it roughly translates into:

  # add_crumb :comment
  before_filter :add_comment_breadcrumb
  def add_comment_breadcrumb
    add_crumb @comment.to_s, @comment
  end

Installation

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

2 Responses to “Introducing Crummy”


  1. 1 Ed P

    Hi Zach, great plug in! The docs make it sound like you can do something like this:


    add_crumb(’My Crumb’) {|c| c.send :home_path}, :except => “faqs”

    But Rails (2.1) gives me this error:


    SyntaxError (/vendor/rails/activesupport/lib/active_support/dependencies.rb:215:in `load_without_new_constant_marking’: /app/controllers/my_controller.rb:5: syntax error, unexpected ‘,’, expecting kEND
    add_crumb(’My Crumb’) {|c| c.send :home_path}, :except => “faqs”
    ^):
    /vendor/gems/mack_ruby_core_extensions-0.1.28/lib/extensions/string.rb:26:in `constantize’

    Do you know what the problem is?

  2. 2 Zach Inglis

    Ed,

    You should be able to do that.

    However, I think it would probably work like this:
    add_crumb(’My Crumb’, :except => “faqs”) {|c| c.send :home_path}

Comments are currently closed.