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

4 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.

  3. # on 07 Nov 08 @ 4:15 Martijn Lafeber said this:

    Brilliant in combination with the rails url-hack for pretty urls.

  4. # on 03 Jun 11 @ 9:05 Scotty Highman said this:

    Great day, might be here is towards problem solely well, i’ve been performing research regarding your web site which’s why it is very evidently professional. I possess been developing a crisp new writings together with making an attempt get back look nice, every time as well as really feel a product i’ve spoil it. Suggestions regarding how onerous was noticed as the to site? Efficiently any particular person considerably enjoy me with out an happening do it, on top of which complete people increase web need to possess of wrecking receiving that carried out as well as?

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.