Agile Web Development

Build it. Launch it. Love it.

acts_as_breadcrumbs

ActsAsBreadcrumbs

In Hansel & Gretel, Hansel drops breadcrumbs along the trail through the forrest to find their way back home. Like Hansel, this plugin adds a breadcrumbs trail attribute based on a base attribute.

Examples

class Location < ActiveRecord::Base
acts_as_tree
acts_as_breadcrumbs(:attr => :location_string)
end

some_location = Location.new(:name => "RM03", :parent => first_floor, :description => "Room 3 on the First Floor")
some_location.location_string #=> "HQ:FL01:RM03"

The above example creates an address for picking inventory.

class Soldier < ActiveRecord::Base
acts_as_tree
acts_as_breadcrumbs(:attr => :chain_o_command, :separator => " > ")
end

mueller = Soldier.new(:name => "LTC Mueller", :parent => stanley)
mueller.chain_o_command #=> "General Hailstone > Colonel Stanley > LTC Mueller"

This example creates a chain of command excluding the root object(The President).

class WebPage < ActiveRecord::Base
include ActionView::Helpers::TagHelper

acts_as_tree
acts_as_breadcrumbs(:attr => :url, :basename => :slug, :separator => "/")
acts_as_breadcrumbs(:basename => :title, :separator => " > ")
end

baz = WebPage.create(:title => "Baz", :parent => bar)
baz.url #=> "foo/bar/baz"
baz.breadcrumbs #=> "Foo > Bar > Baz"

The last example uses two breadcrumbs attributes, one to generate a URL the other to generate a traditional breadcrumbs string.

Vitals

Home http://actsasflinn.com/articles/2007/05/02/acts_as_breadcrumbs
Repository svn://rubyforge.org/var/svn/breadcrumbs/trunk/acts_as_breadcrumbs
License Rails' (MIT)
Tags Tag_red navigation user_interface
Rating (8 votes)
Owner Flinn Mueller
Created 2 May 2007

Comments

  • Avatar
    27 August 2008

    Is anyone having problems with this plugin? I am getting errors with Rails 2.0.2

    The error message: NoMethodError: undefined method `breadcrumbs=' for #<WebPage:0x7ec6e8e0>

    I followed the last example. I'm going to dig into this to see what I can find.

  • Avatar
    27 August 2008

    Ah, a field called 'breadcrumbs'(default) was needed.

Add a comment