Links
acts_as_breadcrumbs
Categories
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 |
navigation user_interface
|
| Rating | (8 votes) |
| Owner | Flinn Mueller |
| Created | 2 May 2007 |
Comments
-
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.
-
Ah, a field called 'breadcrumbs'(default) was needed.

