# Tabbed Menus - link\_to\_unless\_current

**URL:** <https://www.ruby-forum.com/t/tabbed-menus-link-to-unless-current/149886>\
**Category:** Rails\
**Created:** [September 30, 2008, 8:50pm UTC](https://www.ruby-forum.com/t/tabbed-menus-link-to-unless-current/149886 "2008-09-30T20:50:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [September 30, 2008, 8:50pm UTC](https://www.ruby-forum.com/t/tabbed-menus-link-to-unless-current/149886/1 "2008-09-30T20:50:45Z")

</div>

This is more difficult than I originally anticipated. Any help in  
figuring this out is most appreciated:

This is a code snippet from my header.rhtml (or erb) file that draws  
tabbed menus:

```
        <ul>
          <% [["Home", "/home"],
              ["Positions", "/company"],
              ["Leads", "/feed"],
              ["Calendar", "/calendar"],
              ["Contacts", "/contact"],
              ["Documents", "/document"],
              ["My Account", "/account"],
              ["Help", "/help"]].each do |label,

```

controller| %\>  
\<%= open\_tag “li” %\>  
\<%= link\_to\_unless\_current(label,  
{:controller =\> controller}  
) { |label, controller| content\_tag(“span”, label,  
:class =\> “current”) } %\>

This implements “tabbed menus” using special CSS styling for the  
“current” class and works fine.

Here is the twist: each of the tabs, Home for example which has  
corresponding controller given by “/home” displays pages using default  
index action which has further links pointing back to other controllers.  
So a link in the page opened by HomeController index action has a link  
pointing back to the CompanyController (identified above by  
[“Positions”, “/company”] sub-array.

As it is now, as soon as the users click on the links on any pages, the  
current tab disappears since there is no “current” class. Instead, when  
the users click on a link on the page displayed by the index action,  
they still want the “Home” tab hilighted to show the navigation path  
which means it should have the “current” class. In this case,  
link\_to\_unless\_current does not work since there is not current tab or  
link that was clicked on.

How should I go about implementing that?

Bharat
