Created
February 15, 2012 14:28
-
-
Save fayimora/1836140 to your computer and use it in GitHub Desktop.
Navigation builder
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
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