Skip to content

Instantly share code, notes, and snippets.

@fayimora
Created February 15, 2012 14:28
Show Gist options
  • Save fayimora/1836140 to your computer and use it in GitHub Desktop.
Save fayimora/1836140 to your computer and use it in GitHub Desktop.
Navigation builder
module ApplicationHelper
def build_navigation(ls=nil)
ls ||= links
res = ""
ls.each do |link|
if controller.controller_name == link[:url][:controller] && controller.action_name == link[:url][:action]
link[:html_options].merge!({ :class => "#{link[:html_options][:class]} current" } )
end
res << "<li class=\"#{link[:html_options][:class]}\">"
res << link_to(link[:text], link[:url])
res << "</li>"
end
res.html_safe
end
def links
[{:text => "Most Recent", :url => hash_for_root_path, :html_options => { :class => "mostRecent" } },
{:text => "All", :url => hash_for_stories_path, :html_options => { :class => "all" }},
{:text => "About", :url => hash_for_about_path, :html_options => { :class => "about" }},
{:text => "Contact", :url => hash_for_new_contact_path, :html_options => { :class => "contact" }}]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment