Skip to content

Instantly share code, notes, and snippets.

@tmeasday
Created October 2, 2011 08:55
Show Gist options
  • Save tmeasday/1257253 to your computer and use it in GitHub Desktop.
Save tmeasday/1257253 to your computer and use it in GitHub Desktop.
How to use current_page? to do a nav bar in rails
<%# This is completely boilerplate rails %>
<ul id="navbar">
<li><%= link_to_unless_current("Home", home_path) %></li>
<li><%= link_to_unless_current("About Us", about_path) %></li>
</ul>
<%# More specific %>
<ul id="navbar">
<li><%= link_to "Home", home_path, :class => current_page?(home_path) ? 'current' : '' %></li>
<li><%= link_to "About Us", about_path, :class => current_page?(home_path) ? 'current' : '' %></li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment