Skip to content

Instantly share code, notes, and snippets.

@bearroast
Created December 11, 2012 22:13
Show Gist options
  • Save bearroast/4262796 to your computer and use it in GitHub Desktop.
Save bearroast/4262796 to your computer and use it in GitHub Desktop.
<%= nav_link 'Button 1', '/salt', :id => 'fun' %>
<%= nav_link 'Button 2', '/pepper' %>
<%= nav_link 'Button 3', '/thyme' %>
def nav_link(link_text, link_path, more_args = nil)
# link_text: text on the button or link
# link_poth: link url
# more_args: anything you need, like id, alt or title
class_name = current_page?(link_path) ? 'active' : nil # see if current page is on the link path and apply class 'active', else do nothing
content_tag(:li, :class => class_name) do
link_to link_text, link_path, more_args
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment