Skip to content

Instantly share code, notes, and snippets.

@priceflex
Created June 21, 2011 05:55
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 priceflex/1037315 to your computer and use it in GitHub Desktop.
Save priceflex/1037315 to your computer and use it in GitHub Desktop.
EZ Clean Dynamic rails navigation.
module ApplicationHelper
# Simple Navigation
# navigation nav_elements, :selected_class => "foo"
def navigation(links=[],options={})
path = (options[:controller_only] == true) ? controller.controller_name.to_sym : request.path
content_tag :ul, :class => (options[:class] || 'navigation') do
links.each do |link|
klass = (path == link[:path]) ? options[:selected_class] || 'current' : ""
klass = "#{link[:class]} #{klass}"
concat content_tag(:li, link_to(link[:text], link[:path]), :class => klass)
end
end
end
def nav_elements
[
{:path => "", :text => "", :class => "first"},
{:path => root_path, :text => "HOME"},
{:path => before_and_after_path, :text => "About Us", :class => 'bar'},
{:path => "", :text => "", :class => "last"}
]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment