Skip to content

Instantly share code, notes, and snippets.

@gavinlaking
Created June 17, 2010 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavinlaking/442338 to your computer and use it in GitHub Desktop.
Save gavinlaking/442338 to your computer and use it in GitHub Desktop.
This captures paths which are children of the top-level navigation elements, providing you place the routes in the :paths.
def shopkeeper_navigation
contents = ''
links = [
{:label => "Dashboard", :value => shopkeeper_dashboard_path, :paths => []},
{:label => "My Products & Services", :value => shopkeeper_products_path, :paths => [shopkeeper_services_path, shopkeeper_returns_path]},
{:label => "My Customers", :value => shopkeeper_customers_path, :paths => [shopkeeper_promotions]},
{:label => "My Shop", :value => shopkeeper_shop_path, :paths => [shopkeeper_paypal_details_path]},
]
links.each do |link|
if (request.path =~ %r(#{link[:value]}.*)) || (link[:paths].any?{|path| request.path =~ %r(#{path}) })
contents << content_tag(:li, link_to(link[:label], link[:value]), :class => "active")
else
contents << content_tag(:li, link_to(link[:label], link[:value]))
end
end
contents
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment