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.
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.
moduleApplicationHelperdefbreadcrumbs
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(' > ')
endend
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.