Created
March 9, 2012 20:06
-
-
Save nacengineer/2008377 to your computer and use it in GitHub Desktop.
Cool Breadcrumb Method (rails, haml, and memcached?)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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