link_to_unless_current
![Wide documentation Importance_3](https://d2vfyqvduarcvs.cloudfront.net/images/importance_3.png?1349367920)
link_to_unless_current(name, options = {}, html_options = {}, &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). You can give link_to_unless_current a block which will specialize the default behavior (e.g., show a “Start Here” link rather than the link’s text).
Examples
Let’s say you have a navigation menu…
<ul id="navbar"> <li><%= link_to_unless_current("Home", { :action => "index" }) %></li> <li><%= link_to_unless_current("About Us", { :action => "about" }) %></li> </ul>
If in the “about” action, it will render…
<ul id="navbar"> <li><a href="/controller/index">Home</a></li> <li>About Us</li> </ul>
…but if in the “index” action, it will render:
<ul id="navbar"> <li>Home</li> <li><a href="/controller/about">About Us</a></li> </ul>
The implicit block given to link_to_unless_current is evaluated if the current action is the action given. So, if we had a comments page and wanted to render a “Go Back” link instead of a link to the comments page, we could do something like this…
<%= link_to_unless_current("Comment", { :controller => "comments", :action => "new" }) do link_to("Go back", { :controller => "posts", :action => "index" }) end %>
![Default_avatar_30](https://www.gravatar.com/avatar/ea3ff1b44d6b6c958e1b5283ba7a1132?default=http://apidock.com/images/default_avatar_30.png&size=30)
How to use with HAML
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
![Default_avatar_30](https://www.gravatar.com/avatar/3a48b3fce0b0ee05e227876d951abc6b?default=http://apidock.com/images/default_avatar_30.png&size=30)
Another way to use
<%=
link_to_unless_current("Profile", profile_path)
%> also works (instead of pointing to controller/action)