method

link_to_unless_current

link_to_unless_current(name, options = {}, html_options = {}, *parameters_for_method_reference, &block)
public

Creates a link tag of the given name using a URL created by the set of options unless the current request uri is the same as the links, in which case only the name is returned (or the given block is yielded, if one exists). Refer to the documentation for link_to_unless for block usage.

  <ul id="navbar">
    <li><%= link_to_unless_current("Home", { :action => "index" }) %></li>
    <li><%= link_to_unless_current("About Us", { :action => "about" }) %></li>
  </ul>

This will render the following HTML when on the about us page:

  <ul id="navbar">
    <li><a href="/controller/index">Home</a></li>
    <li>About Us</li>
  </ul>

2Notes

How to use with HAML

tordans · Nov 26, 2009

Are you using HAML and try to do the block-thing (do...)? Please note that the whole block has to be in a single line. More: http://groups.google.com/group/haml/browse_thread/thread/52e62ef501c504a3

Another way to use

szadok · Jul 1, 2011
<%= 
link_to_unless_current("Profile", profile_path) 
%>

also works (instead of pointing to controller/action)