The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
the breadcrumbs example

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Obie Fernandez

Posts: 608
Nickname: obie
Registered: Aug, 2005

Obie Fernandez is a Technologist for ThoughtWorks
the breadcrumbs example Posted: Feb 10, 2007 5:43 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Obie Fernandez.
Original Post: the breadcrumbs example
Feed Title: Obie On Rails (Has It Been 9 Years Already?)
Feed URL: http://jroller.com/obie/feed/entries/rss
Feed Description: Obie Fernandez talks about life as a technologist, mostly as ramblings about software development and consulting. Nowadays it's pretty much all about Ruby and Ruby on Rails.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Obie Fernandez
Latest Posts From Obie On Rails (Has It Been 9 Years Already?)

Advertisement

My current project features breadcrumbs, a fairly common dynamic navigation feature which helps the user track where he is on the site.

Given the hierarchical nature of the data presented (cities, neighborhoods, scenes) and the way those models are set up as nested REST resources, I was able to code the implementation of the breadcrumbs feature in an easy to read and understand 5-line helper method.

module ApplicationHelper
  
  def breadcrumbs
    s =  [ link_to('Home', home_path) ]
    s << link_to(@city.name, city_path(@city)) if @city
    s << link_to(@neighborhood.name, neighborhood_path(@city, @neighborhood_path)) if @neighborhood
    s << link_to(@scene.name, scene_path(@city, @neighborhood, @scene)) if @scene
    s.join(' > ')
  end
  
end

I was particularly happy with the elegance of pushing the link elements of the breadcrumb trail onto a Ruby array and joining them with a > character on the last line.


Tired of your job? Need to hire developers? Visit DZone Jobs: great people, great opportunities.

Read: the breadcrumbs example

Topic: Ruby, libxml and Windows Previous Topic   Next Topic Topic: Devalot - New, Rails-Powered Software Project Management Tool

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use