Skip to content

Instantly share code, notes, and snippets.

@mghaught
Created February 27, 2009 20:09
Show Gist options
  • Save mghaught/71668 to your computer and use it in GitHub Desktop.
Save mghaught/71668 to your computer and use it in GitHub Desktop.
# in ApplicationController
def admin_nav
return unless current_user
@sec_nav = []
@current_main = "Admin"
@sec_nav << {:name => "Users", :link => users_path} if admin?
@sec_nav << {:name => "Invites", :link => invites_path} if admin?
end
# in ApplicationHelper
def main_nav
top_nav = []
return top_nav unless current_user
top_nav << {:name => "Dashboard", :link => dashboard_path}
top_nav << {:name => "Character", :link => characters_path}
top_nav << {:name => "Quest", :link => locations_path}
top_nav << {:name => "Admin", :link => users_path} if admin?
top_nav
end
def secondary_nav
return [] unless current_user
@sec_nav || []
end
def current_main
@current_main || controller.controller_name.titleize
end
def current_second
@current_second || controller.controller_name.titleize
end
# specific controller
before_filter :admin_nav
# In layout:
<div id="main-navigation">
<%= render :partial => "shared/navigation", :locals => {:tabs => main_nav, :current => current_main} %>
<div class="clear"></div>
</div>
# navigation partial
<ul>
<% for tab in tabs
cs = []
cs << "first" if tab == tabs.first
cs << "active" if tab[:name] == current
%>
<li class="<%= cs.join(' ') %>"><%= link_to tab[:name], tab[:link] %></li>
<% end %>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment