Skip to content

Instantly share code, notes, and snippets.

@nacengineer
Created March 9, 2012 20:06
Show Gist options
  • Save nacengineer/2008377 to your computer and use it in GitHub Desktop.
Save nacengineer/2008377 to your computer and use it in GitHub Desktop.
Cool Breadcrumb Method (rails, haml, and memcached?)
def active_site_links
# Possible memcache candidate
c = %w{editions forms questions question_answers}
h = c.inject({}) {|a,x| a[x.to_sym] = {:name => x}; a }
if h.has_key? controller.controller_name.to_sym
h[controller.controller_name.to_sym][:active] = true
end
h
end
# this method creates the link_to links for #site-nav
def site_nav_links
capture_haml do
active_site_links.each do |k,v|
haml_tag(:li, :class => v.has_key?(:active) ? 'active' : "") do
haml_concat link_to v[:name], url_for(:controller => v[:name], :action => :index)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment