Tag Archive for 'breadcrumbs'

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 Comments