below is a simple implementation of bread-crumbs for use in ruby on rails, you can pass in the level separator as the first argument and a boolean to indicate inclusion of home link.

it relies on the requested path to work out how to split the breadcrumbs, it alsoo requires that every component of your path is accessable, should be a good starting block though.

  def breadcrumbs(sep = », include_home = true)
    levels = request.path.split(?)[0].split(/)
    levels.delete_at(0)

    links = You are here: 
    links += content_tag(a, home, :href => /) if include_home

    levels.each_with_index do |level, index|
      links +=  #{sep} #{content_tag(a, level.downcase.gsub(/_/,  ), :href => /+levels[0..index].join(/))}
    end

    content_tag(div, content_tag(p, links ), :id => breadcrumb)
  end

2 comments

add your own

  1. # on 11 Mar 08 @ 11:19 Naresh said this:

    Hey..

    I was looking for breadcrumbs for a while in RoR, I haven’t tried your script. Can i know where i should insert this script in my code.

  2. # on 03 Aug 08 @ 4:52 John Yerhot said this:

    @naresh
    you’d wanna put it in a helper, prolly your application helper to use it globally.

your turn

your private data is never published or shared. required fields are marked *

metal&gin?

metal & gin is the personal blog of craig t mackenzie, a scary boy with delusions of grandeur, and a panache for geek-chic. craig lives in the UK and writes code for avenue a | razorfish. you can find out more about him in the about section.

this blog mostly focuses on matters of geekery as well as any random musing that pops into craig's head. this is also a place for meta-data about craig to be collated.