Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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